{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import scipy.stats as stats #统计模块\n",
    "import scipy\n",
    "# import pymysql #导入数据库模块\n",
    "\n",
    "from datetime import datetime #时间模块\n",
    "import statsmodels.formula.api as smf # OLS regression\n",
    "\n",
    "# import pyreadr # read RDS file\n",
    "\n",
    "from matplotlib import style\n",
    "import matplotlib.pyplot as plt #画图模块\n",
    "import matplotlib.dates as mdates\n",
    "\n",
    "from matplotlib.font_manager import FontProperties #作图中文\n",
    "from pylab import mpl\n",
    "\n",
    "# 输出矢量图 渲染矢量图\n",
    "%matplotlib inline\n",
    "%config InlineBackend.figure_format='svg'\n",
    "\n",
    "from IPython.core.interactiveshell import InteractiveShell #jupyter运行输出的模块\n",
    "#显示每一个运行结果\n",
    "InteractiveShell.ast_node_interactivity='all'\n",
    "\n",
    "#设置列不限制数量\n",
    "pd.set_option('display.max_columns',None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>month</th>\n",
       "      <th>price</th>\n",
       "      <th>Rank</th>\n",
       "      <th>Freq</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>sizef</th>\n",
       "      <th>sizet</th>\n",
       "      <th>Return</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>w</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-05-31</td>\n",
       "      <td>38.34</td>\n",
       "      <td>2</td>\n",
       "      <td>24.0</td>\n",
       "      <td>1.016010e+09</td>\n",
       "      <td>1.859497e+09</td>\n",
       "      <td>20.739149</td>\n",
       "      <td>21.343572</td>\n",
       "      <td>-0.122253</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-06-30</td>\n",
       "      <td>33.99</td>\n",
       "      <td>3</td>\n",
       "      <td>23.0</td>\n",
       "      <td>9.007350e+08</td>\n",
       "      <td>1.648521e+09</td>\n",
       "      <td>20.618722</td>\n",
       "      <td>21.223144</td>\n",
       "      <td>-0.113459</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-07-31</td>\n",
       "      <td>29.54</td>\n",
       "      <td>4</td>\n",
       "      <td>16.0</td>\n",
       "      <td>7.828100e+08</td>\n",
       "      <td>1.432695e+09</td>\n",
       "      <td>20.478401</td>\n",
       "      <td>21.082823</td>\n",
       "      <td>-0.130921</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-08-31</td>\n",
       "      <td>15.00</td>\n",
       "      <td>5</td>\n",
       "      <td>15.0</td>\n",
       "      <td>6.748338e+08</td>\n",
       "      <td>1.346275e+09</td>\n",
       "      <td>20.329977</td>\n",
       "      <td>21.020607</td>\n",
       "      <td>-0.411588</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-09-30</td>\n",
       "      <td>14.50</td>\n",
       "      <td>6</td>\n",
       "      <td>24.0</td>\n",
       "      <td>6.523394e+08</td>\n",
       "      <td>1.301399e+09</td>\n",
       "      <td>20.296075</td>\n",
       "      <td>20.986706</td>\n",
       "      <td>-0.033333</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>0.849080</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>752023</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-08-31</td>\n",
       "      <td>13.56</td>\n",
       "      <td>24</td>\n",
       "      <td>23.0</td>\n",
       "      <td>7.955351e+09</td>\n",
       "      <td>1.054667e+10</td>\n",
       "      <td>22.797111</td>\n",
       "      <td>23.079076</td>\n",
       "      <td>-0.025862</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027103</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>752024</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-09-30</td>\n",
       "      <td>14.54</td>\n",
       "      <td>25</td>\n",
       "      <td>20.0</td>\n",
       "      <td>8.530295e+09</td>\n",
       "      <td>1.130889e+10</td>\n",
       "      <td>22.866890</td>\n",
       "      <td>23.148855</td>\n",
       "      <td>0.072271</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>752025</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-10-31</td>\n",
       "      <td>13.85</td>\n",
       "      <td>26</td>\n",
       "      <td>17.0</td>\n",
       "      <td>8.125488e+09</td>\n",
       "      <td>1.077222e+10</td>\n",
       "      <td>22.818272</td>\n",
       "      <td>23.100237</td>\n",
       "      <td>-0.047455</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>752026</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-11-30</td>\n",
       "      <td>13.48</td>\n",
       "      <td>27</td>\n",
       "      <td>22.0</td>\n",
       "      <td>7.908417e+09</td>\n",
       "      <td>1.048444e+10</td>\n",
       "      <td>22.791193</td>\n",
       "      <td>23.073159</td>\n",
       "      <td>-0.026715</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>752027</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>14.89</td>\n",
       "      <td>28</td>\n",
       "      <td>21.0</td>\n",
       "      <td>8.735632e+09</td>\n",
       "      <td>1.158111e+10</td>\n",
       "      <td>22.890676</td>\n",
       "      <td>23.172641</td>\n",
       "      <td>0.104599</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>709883 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd      month  price  Rank  Freq  floatingvalue    totalvalue  \\\n",
       "1       000001 1991-05-31  38.34     2  24.0   1.016010e+09  1.859497e+09   \n",
       "2       000001 1991-06-30  33.99     3  23.0   9.007350e+08  1.648521e+09   \n",
       "3       000001 1991-07-31  29.54     4  16.0   7.828100e+08  1.432695e+09   \n",
       "4       000001 1991-08-31  15.00     5  15.0   6.748338e+08  1.346275e+09   \n",
       "5       000001 1991-09-30  14.50     6  24.0   6.523394e+08  1.301399e+09   \n",
       "...        ...        ...    ...   ...   ...            ...           ...   \n",
       "752023  605599 2023-08-31  13.56    24  23.0   7.955351e+09  1.054667e+10   \n",
       "752024  605599 2023-09-30  14.54    25  20.0   8.530295e+09  1.130889e+10   \n",
       "752025  605599 2023-10-31  13.85    26  17.0   8.125488e+09  1.077222e+10   \n",
       "752026  605599 2023-11-30  13.48    27  22.0   7.908417e+09  1.048444e+10   \n",
       "752027  605599 2023-12-31  14.89    28  21.0   8.735632e+09  1.158111e+10   \n",
       "\n",
       "            sizef      sizet    Return   rfmonth       ret  next_ret  w  \n",
       "1       20.739149  21.343572 -0.122253  0.006092 -0.128345 -0.119551  1  \n",
       "2       20.618722  21.223144 -0.113459  0.006092 -0.119551 -0.137013  1  \n",
       "3       20.478401  21.082823 -0.130921  0.006092 -0.137013 -0.417680  1  \n",
       "4       20.329977  21.020607 -0.411588  0.006092 -0.417680 -0.039425  1  \n",
       "5       20.296075  20.986706 -0.033333  0.006092 -0.039425  0.849080  1  \n",
       "...           ...        ...       ...       ...       ...       ... ..  \n",
       "752023  22.797111  23.079076 -0.025862  0.001241 -0.027103  0.071030  1  \n",
       "752024  22.866890  23.148855  0.072271  0.001241  0.071030 -0.048696  1  \n",
       "752025  22.818272  23.100237 -0.047455  0.001241 -0.048696 -0.027956  1  \n",
       "752026  22.791193  23.073159 -0.026715  0.001241 -0.027956  0.103358  1  \n",
       "752027  22.890676  23.172641  0.104599  0.001241  0.103358       NaN  1  \n",
       "\n",
       "[709883 rows x 14 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cross = pd.read_csv(\"D:/python-homework/python-homework/ret_mon_python2023.csv\")\n",
    "from pandas.tseries.offsets import MonthEnd\n",
    "cross['month'] = pd.to_datetime(cross['month'], format='%Y-%m-%d') + MonthEnd(1)\n",
    "# 补齐股票代码 如果不满6位 在前面补上0\n",
    "cross['Stkcd'] = cross['Stkcd'].apply(lambda x: '{:0>6}'.format(x)) # 6位股票代码\n",
    "cross['w'] = 1\n",
    "cross = cross.dropna(subset=['ret'])#丢掉了收益率缺失的数据\n",
    "cross"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 短期动量 Momentum\n",
    "短期反转 reversal\n",
    "- 在每个月$t$把所有的股票按照这个月收益率的大小分10组，最高收益率叫PMAX，最低收益率叫P1\n",
    "- 月末持有P1，卖出PMAX\n",
    "- 观察投资组合在$t+1$月的表现\n",
    "\n",
    "真正的动量（要注意GAP当月）\n",
    "- 在$t$月，计算股票$t-36$到$t-1$累计收益率，把所有的股票按照累计收益率的大小分10组\n",
    "- 月末持有PMAX，卖出P1\n",
    "- 观察投资组合在$t+1$月的表现"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 策略细节"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>ret</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">1991-01-31</th>\n",
       "      <th>0.1</th>\n",
       "      <td>-0.002031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.2</th>\n",
       "      <td>0.002868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.3</th>\n",
       "      <td>0.006672</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.4</th>\n",
       "      <td>0.010476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.5</th>\n",
       "      <td>0.022318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">2023-12-31</th>\n",
       "      <th>0.5</th>\n",
       "      <td>-0.030481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.6</th>\n",
       "      <td>-0.019060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.7</th>\n",
       "      <td>-0.003987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.8</th>\n",
       "      <td>0.016061</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.9</th>\n",
       "      <td>0.058594</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3564 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                     ret\n",
       "month                   \n",
       "1991-01-31 0.1 -0.002031\n",
       "           0.2  0.002868\n",
       "           0.3  0.006672\n",
       "           0.4  0.010476\n",
       "           0.5  0.022318\n",
       "...                  ...\n",
       "2023-12-31 0.5 -0.030481\n",
       "           0.6 -0.019060\n",
       "           0.7 -0.003987\n",
       "           0.8  0.016061\n",
       "           0.9  0.058594\n",
       "\n",
       "[3564 rows x 1 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fenweishu = pd.DataFrame(\n",
    "    cross.groupby(['month'])['ret'].quantile([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]))#分10组\n",
    "fenweishu\n",
    "#整个代码需要变的是'ret'，输入什么样的变量就会输出什么样的投资组合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>level_1</th>\n",
       "      <th>ret</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1991-01-31</td>\n",
       "      <td>0.1</td>\n",
       "      <td>-0.002031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1991-01-31</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.002868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1991-01-31</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.006672</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1991-01-31</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.010476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1991-01-31</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.022318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3559</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>0.5</td>\n",
       "      <td>-0.030481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3560</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>0.6</td>\n",
       "      <td>-0.019060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3561</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>0.7</td>\n",
       "      <td>-0.003987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3562</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.016061</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3563</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.058594</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3564 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          month  level_1       ret\n",
       "0    1991-01-31      0.1 -0.002031\n",
       "1    1991-01-31      0.2  0.002868\n",
       "2    1991-01-31      0.3  0.006672\n",
       "3    1991-01-31      0.4  0.010476\n",
       "4    1991-01-31      0.5  0.022318\n",
       "...         ...      ...       ...\n",
       "3559 2023-12-31      0.5 -0.030481\n",
       "3560 2023-12-31      0.6 -0.019060\n",
       "3561 2023-12-31      0.7 -0.003987\n",
       "3562 2023-12-31      0.8  0.016061\n",
       "3563 2023-12-31      0.9  0.058594\n",
       "\n",
       "[3564 rows x 3 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fenweishu = fenweishu.reset_index()#把索引去掉\n",
    "fenweishu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>level_1</th>\n",
       "      <th>0.1</th>\n",
       "      <th>0.2</th>\n",
       "      <th>0.3</th>\n",
       "      <th>0.4</th>\n",
       "      <th>0.5</th>\n",
       "      <th>0.6</th>\n",
       "      <th>0.7</th>\n",
       "      <th>0.8</th>\n",
       "      <th>0.9</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1991-01-31</th>\n",
       "      <td>-0.002031</td>\n",
       "      <td>0.002868</td>\n",
       "      <td>0.006672</td>\n",
       "      <td>0.010476</td>\n",
       "      <td>0.022318</td>\n",
       "      <td>0.034159</td>\n",
       "      <td>0.044819</td>\n",
       "      <td>0.055479</td>\n",
       "      <td>0.068586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-02-28</th>\n",
       "      <td>-0.042360</td>\n",
       "      <td>-0.037753</td>\n",
       "      <td>-0.012489</td>\n",
       "      <td>0.005470</td>\n",
       "      <td>0.019315</td>\n",
       "      <td>0.030097</td>\n",
       "      <td>0.034615</td>\n",
       "      <td>0.046888</td>\n",
       "      <td>0.081973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-03-31</th>\n",
       "      <td>-0.133314</td>\n",
       "      <td>-0.133261</td>\n",
       "      <td>-0.127661</td>\n",
       "      <td>-0.092379</td>\n",
       "      <td>-0.069797</td>\n",
       "      <td>-0.065144</td>\n",
       "      <td>-0.054707</td>\n",
       "      <td>-0.030694</td>\n",
       "      <td>0.028608</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-04-30</th>\n",
       "      <td>-0.124371</td>\n",
       "      <td>-0.122867</td>\n",
       "      <td>-0.109328</td>\n",
       "      <td>-0.100079</td>\n",
       "      <td>-0.087628</td>\n",
       "      <td>-0.046745</td>\n",
       "      <td>0.020729</td>\n",
       "      <td>0.073833</td>\n",
       "      <td>0.090508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-31</th>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.202117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.127963</td>\n",
       "      <td>-0.101104</td>\n",
       "      <td>-0.081604</td>\n",
       "      <td>-0.067501</td>\n",
       "      <td>-0.053251</td>\n",
       "      <td>-0.037892</td>\n",
       "      <td>-0.019222</td>\n",
       "      <td>0.004010</td>\n",
       "      <td>0.046254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.077841</td>\n",
       "      <td>-0.048326</td>\n",
       "      <td>-0.030102</td>\n",
       "      <td>-0.016111</td>\n",
       "      <td>-0.004367</td>\n",
       "      <td>0.005559</td>\n",
       "      <td>0.017018</td>\n",
       "      <td>0.033242</td>\n",
       "      <td>0.066314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.104815</td>\n",
       "      <td>-0.070334</td>\n",
       "      <td>-0.049764</td>\n",
       "      <td>-0.033905</td>\n",
       "      <td>-0.020315</td>\n",
       "      <td>-0.006363</td>\n",
       "      <td>0.010970</td>\n",
       "      <td>0.035557</td>\n",
       "      <td>0.078925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>-0.050131</td>\n",
       "      <td>-0.024692</td>\n",
       "      <td>-0.007101</td>\n",
       "      <td>0.006883</td>\n",
       "      <td>0.020630</td>\n",
       "      <td>0.034527</td>\n",
       "      <td>0.050795</td>\n",
       "      <td>0.075465</td>\n",
       "      <td>0.123638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.096007</td>\n",
       "      <td>-0.070909</td>\n",
       "      <td>-0.055072</td>\n",
       "      <td>-0.042784</td>\n",
       "      <td>-0.030481</td>\n",
       "      <td>-0.019060</td>\n",
       "      <td>-0.003987</td>\n",
       "      <td>0.016061</td>\n",
       "      <td>0.058594</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>396 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "level_1          0.1       0.2       0.3       0.4       0.5       0.6  \\\n",
       "month                                                                    \n",
       "1991-01-31 -0.002031  0.002868  0.006672  0.010476  0.022318  0.034159   \n",
       "1991-02-28 -0.042360 -0.037753 -0.012489  0.005470  0.019315  0.030097   \n",
       "1991-03-31 -0.133314 -0.133261 -0.127661 -0.092379 -0.069797 -0.065144   \n",
       "1991-04-30 -0.124371 -0.122867 -0.109328 -0.100079 -0.087628 -0.046745   \n",
       "1991-05-31 -0.129118 -0.128345 -0.120582 -0.036993 -0.031989 -0.006657   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.127963 -0.101104 -0.081604 -0.067501 -0.053251 -0.037892   \n",
       "2023-09-30 -0.077841 -0.048326 -0.030102 -0.016111 -0.004367  0.005559   \n",
       "2023-10-31 -0.104815 -0.070334 -0.049764 -0.033905 -0.020315 -0.006363   \n",
       "2023-11-30 -0.050131 -0.024692 -0.007101  0.006883  0.020630  0.034527   \n",
       "2023-12-31 -0.096007 -0.070909 -0.055072 -0.042784 -0.030481 -0.019060   \n",
       "\n",
       "level_1          0.7       0.8       0.9  \n",
       "month                                     \n",
       "1991-01-31  0.044819  0.055479  0.068586  \n",
       "1991-02-28  0.034615  0.046888  0.081973  \n",
       "1991-03-31 -0.054707 -0.030694  0.028608  \n",
       "1991-04-30  0.020729  0.073833  0.090508  \n",
       "1991-05-31  0.055289  0.080639  0.202117  \n",
       "...              ...       ...       ...  \n",
       "2023-08-31 -0.019222  0.004010  0.046254  \n",
       "2023-09-30  0.017018  0.033242  0.066314  \n",
       "2023-10-31  0.010970  0.035557  0.078925  \n",
       "2023-11-30  0.050795  0.075465  0.123638  \n",
       "2023-12-31 -0.003987  0.016061  0.058594  \n",
       "\n",
       "[396 rows x 9 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据变形 数据长变宽\n",
    "fenweishu = fenweishu.pivot_table(index='month',columns='level_1',values='ret')#pivot的作用是数据变形\n",
    "fenweishu\n",
    "# 如果是数据宽变长,用melt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "      <th>three</th>\n",
       "      <th>four</th>\n",
       "      <th>five</th>\n",
       "      <th>six</th>\n",
       "      <th>seven</th>\n",
       "      <th>eight</th>\n",
       "      <th>nine</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1991-01-31</th>\n",
       "      <td>-0.002031</td>\n",
       "      <td>0.002868</td>\n",
       "      <td>0.006672</td>\n",
       "      <td>0.010476</td>\n",
       "      <td>0.022318</td>\n",
       "      <td>0.034159</td>\n",
       "      <td>0.044819</td>\n",
       "      <td>0.055479</td>\n",
       "      <td>0.068586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-02-28</th>\n",
       "      <td>-0.042360</td>\n",
       "      <td>-0.037753</td>\n",
       "      <td>-0.012489</td>\n",
       "      <td>0.005470</td>\n",
       "      <td>0.019315</td>\n",
       "      <td>0.030097</td>\n",
       "      <td>0.034615</td>\n",
       "      <td>0.046888</td>\n",
       "      <td>0.081973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-03-31</th>\n",
       "      <td>-0.133314</td>\n",
       "      <td>-0.133261</td>\n",
       "      <td>-0.127661</td>\n",
       "      <td>-0.092379</td>\n",
       "      <td>-0.069797</td>\n",
       "      <td>-0.065144</td>\n",
       "      <td>-0.054707</td>\n",
       "      <td>-0.030694</td>\n",
       "      <td>0.028608</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-04-30</th>\n",
       "      <td>-0.124371</td>\n",
       "      <td>-0.122867</td>\n",
       "      <td>-0.109328</td>\n",
       "      <td>-0.100079</td>\n",
       "      <td>-0.087628</td>\n",
       "      <td>-0.046745</td>\n",
       "      <td>0.020729</td>\n",
       "      <td>0.073833</td>\n",
       "      <td>0.090508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-31</th>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.202117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.127963</td>\n",
       "      <td>-0.101104</td>\n",
       "      <td>-0.081604</td>\n",
       "      <td>-0.067501</td>\n",
       "      <td>-0.053251</td>\n",
       "      <td>-0.037892</td>\n",
       "      <td>-0.019222</td>\n",
       "      <td>0.004010</td>\n",
       "      <td>0.046254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.077841</td>\n",
       "      <td>-0.048326</td>\n",
       "      <td>-0.030102</td>\n",
       "      <td>-0.016111</td>\n",
       "      <td>-0.004367</td>\n",
       "      <td>0.005559</td>\n",
       "      <td>0.017018</td>\n",
       "      <td>0.033242</td>\n",
       "      <td>0.066314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.104815</td>\n",
       "      <td>-0.070334</td>\n",
       "      <td>-0.049764</td>\n",
       "      <td>-0.033905</td>\n",
       "      <td>-0.020315</td>\n",
       "      <td>-0.006363</td>\n",
       "      <td>0.010970</td>\n",
       "      <td>0.035557</td>\n",
       "      <td>0.078925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>-0.050131</td>\n",
       "      <td>-0.024692</td>\n",
       "      <td>-0.007101</td>\n",
       "      <td>0.006883</td>\n",
       "      <td>0.020630</td>\n",
       "      <td>0.034527</td>\n",
       "      <td>0.050795</td>\n",
       "      <td>0.075465</td>\n",
       "      <td>0.123638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.096007</td>\n",
       "      <td>-0.070909</td>\n",
       "      <td>-0.055072</td>\n",
       "      <td>-0.042784</td>\n",
       "      <td>-0.030481</td>\n",
       "      <td>-0.019060</td>\n",
       "      <td>-0.003987</td>\n",
       "      <td>0.016061</td>\n",
       "      <td>0.058594</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>396 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 one       two     three      four      five       six  \\\n",
       "month                                                                    \n",
       "1991-01-31 -0.002031  0.002868  0.006672  0.010476  0.022318  0.034159   \n",
       "1991-02-28 -0.042360 -0.037753 -0.012489  0.005470  0.019315  0.030097   \n",
       "1991-03-31 -0.133314 -0.133261 -0.127661 -0.092379 -0.069797 -0.065144   \n",
       "1991-04-30 -0.124371 -0.122867 -0.109328 -0.100079 -0.087628 -0.046745   \n",
       "1991-05-31 -0.129118 -0.128345 -0.120582 -0.036993 -0.031989 -0.006657   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.127963 -0.101104 -0.081604 -0.067501 -0.053251 -0.037892   \n",
       "2023-09-30 -0.077841 -0.048326 -0.030102 -0.016111 -0.004367  0.005559   \n",
       "2023-10-31 -0.104815 -0.070334 -0.049764 -0.033905 -0.020315 -0.006363   \n",
       "2023-11-30 -0.050131 -0.024692 -0.007101  0.006883  0.020630  0.034527   \n",
       "2023-12-31 -0.096007 -0.070909 -0.055072 -0.042784 -0.030481 -0.019060   \n",
       "\n",
       "               seven     eight      nine  \n",
       "month                                     \n",
       "1991-01-31  0.044819  0.055479  0.068586  \n",
       "1991-02-28  0.034615  0.046888  0.081973  \n",
       "1991-03-31 -0.054707 -0.030694  0.028608  \n",
       "1991-04-30  0.020729  0.073833  0.090508  \n",
       "1991-05-31  0.055289  0.080639  0.202117  \n",
       "...              ...       ...       ...  \n",
       "2023-08-31 -0.019222  0.004010  0.046254  \n",
       "2023-09-30  0.017018  0.033242  0.066314  \n",
       "2023-10-31  0.010970  0.035557  0.078925  \n",
       "2023-11-30  0.050795  0.075465  0.123638  \n",
       "2023-12-31 -0.003987  0.016061  0.058594  \n",
       "\n",
       "[396 rows x 9 columns]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fenweishu.columns = ['one','two','three','four','five','six','seven','eight','nine']#改名\n",
    "fenweishu"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 合并回原来的数据表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>month</th>\n",
       "      <th>price</th>\n",
       "      <th>Rank</th>\n",
       "      <th>Freq</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>sizef</th>\n",
       "      <th>sizet</th>\n",
       "      <th>Return</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>w</th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "      <th>three</th>\n",
       "      <th>four</th>\n",
       "      <th>five</th>\n",
       "      <th>six</th>\n",
       "      <th>seven</th>\n",
       "      <th>eight</th>\n",
       "      <th>nine</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-05-31</td>\n",
       "      <td>38.34</td>\n",
       "      <td>2</td>\n",
       "      <td>24.0</td>\n",
       "      <td>1.016010e+09</td>\n",
       "      <td>1.859497e+09</td>\n",
       "      <td>20.739149</td>\n",
       "      <td>21.343572</td>\n",
       "      <td>-0.122253</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.202117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-06-30</td>\n",
       "      <td>33.99</td>\n",
       "      <td>3</td>\n",
       "      <td>23.0</td>\n",
       "      <td>9.007350e+08</td>\n",
       "      <td>1.648521e+09</td>\n",
       "      <td>20.618722</td>\n",
       "      <td>21.223144</td>\n",
       "      <td>-0.113459</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.309901</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.115097</td>\n",
       "      <td>0.166237</td>\n",
       "      <td>0.177858</td>\n",
       "      <td>0.184748</td>\n",
       "      <td>0.190006</td>\n",
       "      <td>0.190283</td>\n",
       "      <td>0.201980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-07-31</td>\n",
       "      <td>29.54</td>\n",
       "      <td>4</td>\n",
       "      <td>16.0</td>\n",
       "      <td>7.828100e+08</td>\n",
       "      <td>1.432695e+09</td>\n",
       "      <td>20.478401</td>\n",
       "      <td>21.082823</td>\n",
       "      <td>-0.130921</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.244184</td>\n",
       "      <td>-0.128701</td>\n",
       "      <td>-0.086966</td>\n",
       "      <td>-0.052277</td>\n",
       "      <td>0.007620</td>\n",
       "      <td>0.067451</td>\n",
       "      <td>0.149691</td>\n",
       "      <td>0.216426</td>\n",
       "      <td>0.246553</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-08-31</td>\n",
       "      <td>15.00</td>\n",
       "      <td>5</td>\n",
       "      <td>15.0</td>\n",
       "      <td>6.748338e+08</td>\n",
       "      <td>1.346275e+09</td>\n",
       "      <td>20.329977</td>\n",
       "      <td>21.020607</td>\n",
       "      <td>-0.411588</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.161430</td>\n",
       "      <td>-0.110028</td>\n",
       "      <td>-0.049934</td>\n",
       "      <td>-0.014296</td>\n",
       "      <td>0.018298</td>\n",
       "      <td>0.060859</td>\n",
       "      <td>0.219168</td>\n",
       "      <td>0.233226</td>\n",
       "      <td>0.238218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-09-30</td>\n",
       "      <td>14.50</td>\n",
       "      <td>6</td>\n",
       "      <td>24.0</td>\n",
       "      <td>6.523394e+08</td>\n",
       "      <td>1.301399e+09</td>\n",
       "      <td>20.296075</td>\n",
       "      <td>20.986706</td>\n",
       "      <td>-0.033333</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>0.849080</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.118675</td>\n",
       "      <td>-0.067377</td>\n",
       "      <td>-0.053691</td>\n",
       "      <td>-0.041891</td>\n",
       "      <td>-0.030783</td>\n",
       "      <td>-0.018184</td>\n",
       "      <td>0.055164</td>\n",
       "      <td>0.175783</td>\n",
       "      <td>0.190067</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709878</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-08-31</td>\n",
       "      <td>13.56</td>\n",
       "      <td>24</td>\n",
       "      <td>23.0</td>\n",
       "      <td>7.955351e+09</td>\n",
       "      <td>1.054667e+10</td>\n",
       "      <td>22.797111</td>\n",
       "      <td>23.079076</td>\n",
       "      <td>-0.025862</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027103</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.127963</td>\n",
       "      <td>-0.101104</td>\n",
       "      <td>-0.081604</td>\n",
       "      <td>-0.067501</td>\n",
       "      <td>-0.053251</td>\n",
       "      <td>-0.037892</td>\n",
       "      <td>-0.019222</td>\n",
       "      <td>0.004010</td>\n",
       "      <td>0.046254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709879</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-09-30</td>\n",
       "      <td>14.54</td>\n",
       "      <td>25</td>\n",
       "      <td>20.0</td>\n",
       "      <td>8.530295e+09</td>\n",
       "      <td>1.130889e+10</td>\n",
       "      <td>22.866890</td>\n",
       "      <td>23.148855</td>\n",
       "      <td>0.072271</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.077841</td>\n",
       "      <td>-0.048326</td>\n",
       "      <td>-0.030102</td>\n",
       "      <td>-0.016111</td>\n",
       "      <td>-0.004367</td>\n",
       "      <td>0.005559</td>\n",
       "      <td>0.017018</td>\n",
       "      <td>0.033242</td>\n",
       "      <td>0.066314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709880</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-10-31</td>\n",
       "      <td>13.85</td>\n",
       "      <td>26</td>\n",
       "      <td>17.0</td>\n",
       "      <td>8.125488e+09</td>\n",
       "      <td>1.077222e+10</td>\n",
       "      <td>22.818272</td>\n",
       "      <td>23.100237</td>\n",
       "      <td>-0.047455</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.104815</td>\n",
       "      <td>-0.070334</td>\n",
       "      <td>-0.049764</td>\n",
       "      <td>-0.033905</td>\n",
       "      <td>-0.020315</td>\n",
       "      <td>-0.006363</td>\n",
       "      <td>0.010970</td>\n",
       "      <td>0.035557</td>\n",
       "      <td>0.078925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709881</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-11-30</td>\n",
       "      <td>13.48</td>\n",
       "      <td>27</td>\n",
       "      <td>22.0</td>\n",
       "      <td>7.908417e+09</td>\n",
       "      <td>1.048444e+10</td>\n",
       "      <td>22.791193</td>\n",
       "      <td>23.073159</td>\n",
       "      <td>-0.026715</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.050131</td>\n",
       "      <td>-0.024692</td>\n",
       "      <td>-0.007101</td>\n",
       "      <td>0.006883</td>\n",
       "      <td>0.020630</td>\n",
       "      <td>0.034527</td>\n",
       "      <td>0.050795</td>\n",
       "      <td>0.075465</td>\n",
       "      <td>0.123638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709882</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>14.89</td>\n",
       "      <td>28</td>\n",
       "      <td>21.0</td>\n",
       "      <td>8.735632e+09</td>\n",
       "      <td>1.158111e+10</td>\n",
       "      <td>22.890676</td>\n",
       "      <td>23.172641</td>\n",
       "      <td>0.104599</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.096007</td>\n",
       "      <td>-0.070909</td>\n",
       "      <td>-0.055072</td>\n",
       "      <td>-0.042784</td>\n",
       "      <td>-0.030481</td>\n",
       "      <td>-0.019060</td>\n",
       "      <td>-0.003987</td>\n",
       "      <td>0.016061</td>\n",
       "      <td>0.058594</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>709883 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd      month  price  Rank  Freq  floatingvalue    totalvalue  \\\n",
       "0       000001 1991-05-31  38.34     2  24.0   1.016010e+09  1.859497e+09   \n",
       "1       000001 1991-06-30  33.99     3  23.0   9.007350e+08  1.648521e+09   \n",
       "2       000001 1991-07-31  29.54     4  16.0   7.828100e+08  1.432695e+09   \n",
       "3       000001 1991-08-31  15.00     5  15.0   6.748338e+08  1.346275e+09   \n",
       "4       000001 1991-09-30  14.50     6  24.0   6.523394e+08  1.301399e+09   \n",
       "...        ...        ...    ...   ...   ...            ...           ...   \n",
       "709878  605599 2023-08-31  13.56    24  23.0   7.955351e+09  1.054667e+10   \n",
       "709879  605599 2023-09-30  14.54    25  20.0   8.530295e+09  1.130889e+10   \n",
       "709880  605599 2023-10-31  13.85    26  17.0   8.125488e+09  1.077222e+10   \n",
       "709881  605599 2023-11-30  13.48    27  22.0   7.908417e+09  1.048444e+10   \n",
       "709882  605599 2023-12-31  14.89    28  21.0   8.735632e+09  1.158111e+10   \n",
       "\n",
       "            sizef      sizet    Return   rfmonth       ret  next_ret  w  \\\n",
       "0       20.739149  21.343572 -0.122253  0.006092 -0.128345 -0.119551  1   \n",
       "1       20.618722  21.223144 -0.113459  0.006092 -0.119551 -0.137013  1   \n",
       "2       20.478401  21.082823 -0.130921  0.006092 -0.137013 -0.417680  1   \n",
       "3       20.329977  21.020607 -0.411588  0.006092 -0.417680 -0.039425  1   \n",
       "4       20.296075  20.986706 -0.033333  0.006092 -0.039425  0.849080  1   \n",
       "...           ...        ...       ...       ...       ...       ... ..   \n",
       "709878  22.797111  23.079076 -0.025862  0.001241 -0.027103  0.071030  1   \n",
       "709879  22.866890  23.148855  0.072271  0.001241  0.071030 -0.048696  1   \n",
       "709880  22.818272  23.100237 -0.047455  0.001241 -0.048696 -0.027956  1   \n",
       "709881  22.791193  23.073159 -0.026715  0.001241 -0.027956  0.103358  1   \n",
       "709882  22.890676  23.172641  0.104599  0.001241  0.103358       NaN  1   \n",
       "\n",
       "             one       two     three      four      five       six     seven  \\\n",
       "0      -0.129118 -0.128345 -0.120582 -0.036993 -0.031989 -0.006657  0.055289   \n",
       "1      -0.309901 -0.119551 -0.115097  0.166237  0.177858  0.184748  0.190006   \n",
       "2      -0.244184 -0.128701 -0.086966 -0.052277  0.007620  0.067451  0.149691   \n",
       "3      -0.161430 -0.110028 -0.049934 -0.014296  0.018298  0.060859  0.219168   \n",
       "4      -0.118675 -0.067377 -0.053691 -0.041891 -0.030783 -0.018184  0.055164   \n",
       "...          ...       ...       ...       ...       ...       ...       ...   \n",
       "709878 -0.127963 -0.101104 -0.081604 -0.067501 -0.053251 -0.037892 -0.019222   \n",
       "709879 -0.077841 -0.048326 -0.030102 -0.016111 -0.004367  0.005559  0.017018   \n",
       "709880 -0.104815 -0.070334 -0.049764 -0.033905 -0.020315 -0.006363  0.010970   \n",
       "709881 -0.050131 -0.024692 -0.007101  0.006883  0.020630  0.034527  0.050795   \n",
       "709882 -0.096007 -0.070909 -0.055072 -0.042784 -0.030481 -0.019060 -0.003987   \n",
       "\n",
       "           eight      nine  \n",
       "0       0.080639  0.202117  \n",
       "1       0.190283  0.201980  \n",
       "2       0.216426  0.246553  \n",
       "3       0.233226  0.238218  \n",
       "4       0.175783  0.190067  \n",
       "...          ...       ...  \n",
       "709878  0.004010  0.046254  \n",
       "709879  0.033242  0.066314  \n",
       "709880  0.035557  0.078925  \n",
       "709881  0.075465  0.123638  \n",
       "709882  0.016061  0.058594  \n",
       "\n",
       "[709883 rows x 23 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio = pd.merge(cross,fenweishu,on='month',how='left')#小表往大表里填充\n",
    "portfolio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>month</th>\n",
       "      <th>price</th>\n",
       "      <th>Rank</th>\n",
       "      <th>Freq</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>sizef</th>\n",
       "      <th>sizet</th>\n",
       "      <th>Return</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>w</th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "      <th>three</th>\n",
       "      <th>four</th>\n",
       "      <th>five</th>\n",
       "      <th>six</th>\n",
       "      <th>seven</th>\n",
       "      <th>eight</th>\n",
       "      <th>nine</th>\n",
       "      <th>sort</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-05-31</td>\n",
       "      <td>38.34</td>\n",
       "      <td>2</td>\n",
       "      <td>24.0</td>\n",
       "      <td>1.016010e+09</td>\n",
       "      <td>1.859497e+09</td>\n",
       "      <td>20.739149</td>\n",
       "      <td>21.343572</td>\n",
       "      <td>-0.122253</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.202117</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-06-30</td>\n",
       "      <td>33.99</td>\n",
       "      <td>3</td>\n",
       "      <td>23.0</td>\n",
       "      <td>9.007350e+08</td>\n",
       "      <td>1.648521e+09</td>\n",
       "      <td>20.618722</td>\n",
       "      <td>21.223144</td>\n",
       "      <td>-0.113459</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.309901</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.115097</td>\n",
       "      <td>0.166237</td>\n",
       "      <td>0.177858</td>\n",
       "      <td>0.184748</td>\n",
       "      <td>0.190006</td>\n",
       "      <td>0.190283</td>\n",
       "      <td>0.201980</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-07-31</td>\n",
       "      <td>29.54</td>\n",
       "      <td>4</td>\n",
       "      <td>16.0</td>\n",
       "      <td>7.828100e+08</td>\n",
       "      <td>1.432695e+09</td>\n",
       "      <td>20.478401</td>\n",
       "      <td>21.082823</td>\n",
       "      <td>-0.130921</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.244184</td>\n",
       "      <td>-0.128701</td>\n",
       "      <td>-0.086966</td>\n",
       "      <td>-0.052277</td>\n",
       "      <td>0.007620</td>\n",
       "      <td>0.067451</td>\n",
       "      <td>0.149691</td>\n",
       "      <td>0.216426</td>\n",
       "      <td>0.246553</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-08-31</td>\n",
       "      <td>15.00</td>\n",
       "      <td>5</td>\n",
       "      <td>15.0</td>\n",
       "      <td>6.748338e+08</td>\n",
       "      <td>1.346275e+09</td>\n",
       "      <td>20.329977</td>\n",
       "      <td>21.020607</td>\n",
       "      <td>-0.411588</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.161430</td>\n",
       "      <td>-0.110028</td>\n",
       "      <td>-0.049934</td>\n",
       "      <td>-0.014296</td>\n",
       "      <td>0.018298</td>\n",
       "      <td>0.060859</td>\n",
       "      <td>0.219168</td>\n",
       "      <td>0.233226</td>\n",
       "      <td>0.238218</td>\n",
       "      <td>P1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-09-30</td>\n",
       "      <td>14.50</td>\n",
       "      <td>6</td>\n",
       "      <td>24.0</td>\n",
       "      <td>6.523394e+08</td>\n",
       "      <td>1.301399e+09</td>\n",
       "      <td>20.296075</td>\n",
       "      <td>20.986706</td>\n",
       "      <td>-0.033333</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>0.849080</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.118675</td>\n",
       "      <td>-0.067377</td>\n",
       "      <td>-0.053691</td>\n",
       "      <td>-0.041891</td>\n",
       "      <td>-0.030783</td>\n",
       "      <td>-0.018184</td>\n",
       "      <td>0.055164</td>\n",
       "      <td>0.175783</td>\n",
       "      <td>0.190067</td>\n",
       "      <td>P5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709878</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-08-31</td>\n",
       "      <td>13.56</td>\n",
       "      <td>24</td>\n",
       "      <td>23.0</td>\n",
       "      <td>7.955351e+09</td>\n",
       "      <td>1.054667e+10</td>\n",
       "      <td>22.797111</td>\n",
       "      <td>23.079076</td>\n",
       "      <td>-0.025862</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027103</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.127963</td>\n",
       "      <td>-0.101104</td>\n",
       "      <td>-0.081604</td>\n",
       "      <td>-0.067501</td>\n",
       "      <td>-0.053251</td>\n",
       "      <td>-0.037892</td>\n",
       "      <td>-0.019222</td>\n",
       "      <td>0.004010</td>\n",
       "      <td>0.046254</td>\n",
       "      <td>P7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709879</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-09-30</td>\n",
       "      <td>14.54</td>\n",
       "      <td>25</td>\n",
       "      <td>20.0</td>\n",
       "      <td>8.530295e+09</td>\n",
       "      <td>1.130889e+10</td>\n",
       "      <td>22.866890</td>\n",
       "      <td>23.148855</td>\n",
       "      <td>0.072271</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.077841</td>\n",
       "      <td>-0.048326</td>\n",
       "      <td>-0.030102</td>\n",
       "      <td>-0.016111</td>\n",
       "      <td>-0.004367</td>\n",
       "      <td>0.005559</td>\n",
       "      <td>0.017018</td>\n",
       "      <td>0.033242</td>\n",
       "      <td>0.066314</td>\n",
       "      <td>Pmax</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709880</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-10-31</td>\n",
       "      <td>13.85</td>\n",
       "      <td>26</td>\n",
       "      <td>17.0</td>\n",
       "      <td>8.125488e+09</td>\n",
       "      <td>1.077222e+10</td>\n",
       "      <td>22.818272</td>\n",
       "      <td>23.100237</td>\n",
       "      <td>-0.047455</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.104815</td>\n",
       "      <td>-0.070334</td>\n",
       "      <td>-0.049764</td>\n",
       "      <td>-0.033905</td>\n",
       "      <td>-0.020315</td>\n",
       "      <td>-0.006363</td>\n",
       "      <td>0.010970</td>\n",
       "      <td>0.035557</td>\n",
       "      <td>0.078925</td>\n",
       "      <td>P4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709881</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-11-30</td>\n",
       "      <td>13.48</td>\n",
       "      <td>27</td>\n",
       "      <td>22.0</td>\n",
       "      <td>7.908417e+09</td>\n",
       "      <td>1.048444e+10</td>\n",
       "      <td>22.791193</td>\n",
       "      <td>23.073159</td>\n",
       "      <td>-0.026715</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.050131</td>\n",
       "      <td>-0.024692</td>\n",
       "      <td>-0.007101</td>\n",
       "      <td>0.006883</td>\n",
       "      <td>0.020630</td>\n",
       "      <td>0.034527</td>\n",
       "      <td>0.050795</td>\n",
       "      <td>0.075465</td>\n",
       "      <td>0.123638</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709882</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>14.89</td>\n",
       "      <td>28</td>\n",
       "      <td>21.0</td>\n",
       "      <td>8.735632e+09</td>\n",
       "      <td>1.158111e+10</td>\n",
       "      <td>22.890676</td>\n",
       "      <td>23.172641</td>\n",
       "      <td>0.104599</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.096007</td>\n",
       "      <td>-0.070909</td>\n",
       "      <td>-0.055072</td>\n",
       "      <td>-0.042784</td>\n",
       "      <td>-0.030481</td>\n",
       "      <td>-0.019060</td>\n",
       "      <td>-0.003987</td>\n",
       "      <td>0.016061</td>\n",
       "      <td>0.058594</td>\n",
       "      <td>Pmax</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>709883 rows × 24 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd      month  price  Rank  Freq  floatingvalue    totalvalue  \\\n",
       "0       000001 1991-05-31  38.34     2  24.0   1.016010e+09  1.859497e+09   \n",
       "1       000001 1991-06-30  33.99     3  23.0   9.007350e+08  1.648521e+09   \n",
       "2       000001 1991-07-31  29.54     4  16.0   7.828100e+08  1.432695e+09   \n",
       "3       000001 1991-08-31  15.00     5  15.0   6.748338e+08  1.346275e+09   \n",
       "4       000001 1991-09-30  14.50     6  24.0   6.523394e+08  1.301399e+09   \n",
       "...        ...        ...    ...   ...   ...            ...           ...   \n",
       "709878  605599 2023-08-31  13.56    24  23.0   7.955351e+09  1.054667e+10   \n",
       "709879  605599 2023-09-30  14.54    25  20.0   8.530295e+09  1.130889e+10   \n",
       "709880  605599 2023-10-31  13.85    26  17.0   8.125488e+09  1.077222e+10   \n",
       "709881  605599 2023-11-30  13.48    27  22.0   7.908417e+09  1.048444e+10   \n",
       "709882  605599 2023-12-31  14.89    28  21.0   8.735632e+09  1.158111e+10   \n",
       "\n",
       "            sizef      sizet    Return   rfmonth       ret  next_ret  w  \\\n",
       "0       20.739149  21.343572 -0.122253  0.006092 -0.128345 -0.119551  1   \n",
       "1       20.618722  21.223144 -0.113459  0.006092 -0.119551 -0.137013  1   \n",
       "2       20.478401  21.082823 -0.130921  0.006092 -0.137013 -0.417680  1   \n",
       "3       20.329977  21.020607 -0.411588  0.006092 -0.417680 -0.039425  1   \n",
       "4       20.296075  20.986706 -0.033333  0.006092 -0.039425  0.849080  1   \n",
       "...           ...        ...       ...       ...       ...       ... ..   \n",
       "709878  22.797111  23.079076 -0.025862  0.001241 -0.027103  0.071030  1   \n",
       "709879  22.866890  23.148855  0.072271  0.001241  0.071030 -0.048696  1   \n",
       "709880  22.818272  23.100237 -0.047455  0.001241 -0.048696 -0.027956  1   \n",
       "709881  22.791193  23.073159 -0.026715  0.001241 -0.027956  0.103358  1   \n",
       "709882  22.890676  23.172641  0.104599  0.001241  0.103358       NaN  1   \n",
       "\n",
       "             one       two     three      four      five       six     seven  \\\n",
       "0      -0.129118 -0.128345 -0.120582 -0.036993 -0.031989 -0.006657  0.055289   \n",
       "1      -0.309901 -0.119551 -0.115097  0.166237  0.177858  0.184748  0.190006   \n",
       "2      -0.244184 -0.128701 -0.086966 -0.052277  0.007620  0.067451  0.149691   \n",
       "3      -0.161430 -0.110028 -0.049934 -0.014296  0.018298  0.060859  0.219168   \n",
       "4      -0.118675 -0.067377 -0.053691 -0.041891 -0.030783 -0.018184  0.055164   \n",
       "...          ...       ...       ...       ...       ...       ...       ...   \n",
       "709878 -0.127963 -0.101104 -0.081604 -0.067501 -0.053251 -0.037892 -0.019222   \n",
       "709879 -0.077841 -0.048326 -0.030102 -0.016111 -0.004367  0.005559  0.017018   \n",
       "709880 -0.104815 -0.070334 -0.049764 -0.033905 -0.020315 -0.006363  0.010970   \n",
       "709881 -0.050131 -0.024692 -0.007101  0.006883  0.020630  0.034527  0.050795   \n",
       "709882 -0.096007 -0.070909 -0.055072 -0.042784 -0.030481 -0.019060 -0.003987   \n",
       "\n",
       "           eight      nine  sort  \n",
       "0       0.080639  0.202117    P2  \n",
       "1       0.190283  0.201980    P2  \n",
       "2       0.216426  0.246553    P2  \n",
       "3       0.233226  0.238218    P1  \n",
       "4       0.175783  0.190067    P5  \n",
       "...          ...       ...   ...  \n",
       "709878  0.004010  0.046254    P7  \n",
       "709879  0.033242  0.066314  Pmax  \n",
       "709880  0.035557  0.078925    P4  \n",
       "709881  0.075465  0.123638    P2  \n",
       "709882  0.016061  0.058594  Pmax  \n",
       "\n",
       "[709883 rows x 24 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# where if else (if else)\n",
    "portfolio['sort'] = np.where(\n",
    "    portfolio['ret'] <= portfolio['one'], 'P1',\n",
    "    np.where(\n",
    "        portfolio['ret'] <= portfolio['two'], 'P2',\n",
    "        np.where(\n",
    "            portfolio['ret'] <= portfolio['three'], 'P3',\n",
    "            np.where(\n",
    "                portfolio['ret'] <= portfolio['four'], 'P4',\n",
    "                np.where(\n",
    "                    portfolio['ret'] <= portfolio['five'], 'P5',\n",
    "                    np.where(\n",
    "                        portfolio['ret'] <= portfolio['six'], 'P6',\n",
    "                        np.where(\n",
    "                            portfolio['ret'] <= portfolio['seven'], 'P7',\n",
    "                            np.where(\n",
    "                                portfolio['ret'] <= portfolio['eight'], 'P8',\n",
    "                                np.where(\n",
    "                                    portfolio['ret'] <= portfolio['nine'],\n",
    "                                    'P9', 'Pmax')))))))))#生成了新的列sort\n",
    "portfolio"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 投资策略\n",
    "选择和收益率线性相关的变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>month</th>\n",
       "      <th>price</th>\n",
       "      <th>Rank</th>\n",
       "      <th>Freq</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>sizef</th>\n",
       "      <th>sizet</th>\n",
       "      <th>Return</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>w</th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "      <th>three</th>\n",
       "      <th>four</th>\n",
       "      <th>five</th>\n",
       "      <th>six</th>\n",
       "      <th>seven</th>\n",
       "      <th>eight</th>\n",
       "      <th>nine</th>\n",
       "      <th>sort</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-05-31</td>\n",
       "      <td>38.34</td>\n",
       "      <td>2</td>\n",
       "      <td>24.0</td>\n",
       "      <td>1.016010e+09</td>\n",
       "      <td>1.859497e+09</td>\n",
       "      <td>20.739149</td>\n",
       "      <td>21.343572</td>\n",
       "      <td>-0.122253</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.202117</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-06-30</td>\n",
       "      <td>33.99</td>\n",
       "      <td>3</td>\n",
       "      <td>23.0</td>\n",
       "      <td>9.007350e+08</td>\n",
       "      <td>1.648521e+09</td>\n",
       "      <td>20.618722</td>\n",
       "      <td>21.223144</td>\n",
       "      <td>-0.113459</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.309901</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.115097</td>\n",
       "      <td>0.166237</td>\n",
       "      <td>0.177858</td>\n",
       "      <td>0.184748</td>\n",
       "      <td>0.190006</td>\n",
       "      <td>0.190283</td>\n",
       "      <td>0.201980</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-07-31</td>\n",
       "      <td>29.54</td>\n",
       "      <td>4</td>\n",
       "      <td>16.0</td>\n",
       "      <td>7.828100e+08</td>\n",
       "      <td>1.432695e+09</td>\n",
       "      <td>20.478401</td>\n",
       "      <td>21.082823</td>\n",
       "      <td>-0.130921</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.244184</td>\n",
       "      <td>-0.128701</td>\n",
       "      <td>-0.086966</td>\n",
       "      <td>-0.052277</td>\n",
       "      <td>0.007620</td>\n",
       "      <td>0.067451</td>\n",
       "      <td>0.149691</td>\n",
       "      <td>0.216426</td>\n",
       "      <td>0.246553</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-08-31</td>\n",
       "      <td>15.00</td>\n",
       "      <td>5</td>\n",
       "      <td>15.0</td>\n",
       "      <td>6.748338e+08</td>\n",
       "      <td>1.346275e+09</td>\n",
       "      <td>20.329977</td>\n",
       "      <td>21.020607</td>\n",
       "      <td>-0.411588</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.161430</td>\n",
       "      <td>-0.110028</td>\n",
       "      <td>-0.049934</td>\n",
       "      <td>-0.014296</td>\n",
       "      <td>0.018298</td>\n",
       "      <td>0.060859</td>\n",
       "      <td>0.219168</td>\n",
       "      <td>0.233226</td>\n",
       "      <td>0.238218</td>\n",
       "      <td>P1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-09-30</td>\n",
       "      <td>14.50</td>\n",
       "      <td>6</td>\n",
       "      <td>24.0</td>\n",
       "      <td>6.523394e+08</td>\n",
       "      <td>1.301399e+09</td>\n",
       "      <td>20.296075</td>\n",
       "      <td>20.986706</td>\n",
       "      <td>-0.033333</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>0.849080</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.118675</td>\n",
       "      <td>-0.067377</td>\n",
       "      <td>-0.053691</td>\n",
       "      <td>-0.041891</td>\n",
       "      <td>-0.030783</td>\n",
       "      <td>-0.018184</td>\n",
       "      <td>0.055164</td>\n",
       "      <td>0.175783</td>\n",
       "      <td>0.190067</td>\n",
       "      <td>P5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709877</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-07-31</td>\n",
       "      <td>13.92</td>\n",
       "      <td>23</td>\n",
       "      <td>21.0</td>\n",
       "      <td>8.166555e+09</td>\n",
       "      <td>1.082667e+10</td>\n",
       "      <td>22.823313</td>\n",
       "      <td>23.105278</td>\n",
       "      <td>0.053747</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.052506</td>\n",
       "      <td>-0.027103</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.109131</td>\n",
       "      <td>-0.061730</td>\n",
       "      <td>-0.031833</td>\n",
       "      <td>-0.004677</td>\n",
       "      <td>0.018420</td>\n",
       "      <td>0.038359</td>\n",
       "      <td>0.058412</td>\n",
       "      <td>0.084426</td>\n",
       "      <td>0.130416</td>\n",
       "      <td>P7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709878</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-08-31</td>\n",
       "      <td>13.56</td>\n",
       "      <td>24</td>\n",
       "      <td>23.0</td>\n",
       "      <td>7.955351e+09</td>\n",
       "      <td>1.054667e+10</td>\n",
       "      <td>22.797111</td>\n",
       "      <td>23.079076</td>\n",
       "      <td>-0.025862</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027103</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.127963</td>\n",
       "      <td>-0.101104</td>\n",
       "      <td>-0.081604</td>\n",
       "      <td>-0.067501</td>\n",
       "      <td>-0.053251</td>\n",
       "      <td>-0.037892</td>\n",
       "      <td>-0.019222</td>\n",
       "      <td>0.004010</td>\n",
       "      <td>0.046254</td>\n",
       "      <td>P7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709879</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-09-30</td>\n",
       "      <td>14.54</td>\n",
       "      <td>25</td>\n",
       "      <td>20.0</td>\n",
       "      <td>8.530295e+09</td>\n",
       "      <td>1.130889e+10</td>\n",
       "      <td>22.866890</td>\n",
       "      <td>23.148855</td>\n",
       "      <td>0.072271</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.077841</td>\n",
       "      <td>-0.048326</td>\n",
       "      <td>-0.030102</td>\n",
       "      <td>-0.016111</td>\n",
       "      <td>-0.004367</td>\n",
       "      <td>0.005559</td>\n",
       "      <td>0.017018</td>\n",
       "      <td>0.033242</td>\n",
       "      <td>0.066314</td>\n",
       "      <td>Pmax</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709880</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-10-31</td>\n",
       "      <td>13.85</td>\n",
       "      <td>26</td>\n",
       "      <td>17.0</td>\n",
       "      <td>8.125488e+09</td>\n",
       "      <td>1.077222e+10</td>\n",
       "      <td>22.818272</td>\n",
       "      <td>23.100237</td>\n",
       "      <td>-0.047455</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.104815</td>\n",
       "      <td>-0.070334</td>\n",
       "      <td>-0.049764</td>\n",
       "      <td>-0.033905</td>\n",
       "      <td>-0.020315</td>\n",
       "      <td>-0.006363</td>\n",
       "      <td>0.010970</td>\n",
       "      <td>0.035557</td>\n",
       "      <td>0.078925</td>\n",
       "      <td>P4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709881</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-11-30</td>\n",
       "      <td>13.48</td>\n",
       "      <td>27</td>\n",
       "      <td>22.0</td>\n",
       "      <td>7.908417e+09</td>\n",
       "      <td>1.048444e+10</td>\n",
       "      <td>22.791193</td>\n",
       "      <td>23.073159</td>\n",
       "      <td>-0.026715</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.050131</td>\n",
       "      <td>-0.024692</td>\n",
       "      <td>-0.007101</td>\n",
       "      <td>0.006883</td>\n",
       "      <td>0.020630</td>\n",
       "      <td>0.034527</td>\n",
       "      <td>0.050795</td>\n",
       "      <td>0.075465</td>\n",
       "      <td>0.123638</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>700739 rows × 24 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd      month  price  Rank  Freq  floatingvalue    totalvalue  \\\n",
       "0       000001 1991-05-31  38.34     2  24.0   1.016010e+09  1.859497e+09   \n",
       "1       000001 1991-06-30  33.99     3  23.0   9.007350e+08  1.648521e+09   \n",
       "2       000001 1991-07-31  29.54     4  16.0   7.828100e+08  1.432695e+09   \n",
       "3       000001 1991-08-31  15.00     5  15.0   6.748338e+08  1.346275e+09   \n",
       "4       000001 1991-09-30  14.50     6  24.0   6.523394e+08  1.301399e+09   \n",
       "...        ...        ...    ...   ...   ...            ...           ...   \n",
       "709877  605599 2023-07-31  13.92    23  21.0   8.166555e+09  1.082667e+10   \n",
       "709878  605599 2023-08-31  13.56    24  23.0   7.955351e+09  1.054667e+10   \n",
       "709879  605599 2023-09-30  14.54    25  20.0   8.530295e+09  1.130889e+10   \n",
       "709880  605599 2023-10-31  13.85    26  17.0   8.125488e+09  1.077222e+10   \n",
       "709881  605599 2023-11-30  13.48    27  22.0   7.908417e+09  1.048444e+10   \n",
       "\n",
       "            sizef      sizet    Return   rfmonth       ret  next_ret  w  \\\n",
       "0       20.739149  21.343572 -0.122253  0.006092 -0.128345 -0.119551  1   \n",
       "1       20.618722  21.223144 -0.113459  0.006092 -0.119551 -0.137013  1   \n",
       "2       20.478401  21.082823 -0.130921  0.006092 -0.137013 -0.417680  1   \n",
       "3       20.329977  21.020607 -0.411588  0.006092 -0.417680 -0.039425  1   \n",
       "4       20.296075  20.986706 -0.033333  0.006092 -0.039425  0.849080  1   \n",
       "...           ...        ...       ...       ...       ...       ... ..   \n",
       "709877  22.823313  23.105278  0.053747  0.001241  0.052506 -0.027103  1   \n",
       "709878  22.797111  23.079076 -0.025862  0.001241 -0.027103  0.071030  1   \n",
       "709879  22.866890  23.148855  0.072271  0.001241  0.071030 -0.048696  1   \n",
       "709880  22.818272  23.100237 -0.047455  0.001241 -0.048696 -0.027956  1   \n",
       "709881  22.791193  23.073159 -0.026715  0.001241 -0.027956  0.103358  1   \n",
       "\n",
       "             one       two     three      four      five       six     seven  \\\n",
       "0      -0.129118 -0.128345 -0.120582 -0.036993 -0.031989 -0.006657  0.055289   \n",
       "1      -0.309901 -0.119551 -0.115097  0.166237  0.177858  0.184748  0.190006   \n",
       "2      -0.244184 -0.128701 -0.086966 -0.052277  0.007620  0.067451  0.149691   \n",
       "3      -0.161430 -0.110028 -0.049934 -0.014296  0.018298  0.060859  0.219168   \n",
       "4      -0.118675 -0.067377 -0.053691 -0.041891 -0.030783 -0.018184  0.055164   \n",
       "...          ...       ...       ...       ...       ...       ...       ...   \n",
       "709877 -0.109131 -0.061730 -0.031833 -0.004677  0.018420  0.038359  0.058412   \n",
       "709878 -0.127963 -0.101104 -0.081604 -0.067501 -0.053251 -0.037892 -0.019222   \n",
       "709879 -0.077841 -0.048326 -0.030102 -0.016111 -0.004367  0.005559  0.017018   \n",
       "709880 -0.104815 -0.070334 -0.049764 -0.033905 -0.020315 -0.006363  0.010970   \n",
       "709881 -0.050131 -0.024692 -0.007101  0.006883  0.020630  0.034527  0.050795   \n",
       "\n",
       "           eight      nine  sort  \n",
       "0       0.080639  0.202117    P2  \n",
       "1       0.190283  0.201980    P2  \n",
       "2       0.216426  0.246553    P2  \n",
       "3       0.233226  0.238218    P1  \n",
       "4       0.175783  0.190067    P5  \n",
       "...          ...       ...   ...  \n",
       "709877  0.084426  0.130416    P7  \n",
       "709878  0.004010  0.046254    P7  \n",
       "709879  0.033242  0.066314  Pmax  \n",
       "709880  0.035557  0.078925    P4  \n",
       "709881  0.075465  0.123638    P2  \n",
       "\n",
       "[700739 rows x 24 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio = portfolio.dropna(subset=['next_ret','floatingvalue'])#把缺失值丢掉，'next_ret','floatingvalue'中不能有缺失值\n",
    "portfolio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th>sort</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">1991-01-31</th>\n",
       "      <th>P1</th>\n",
       "      <td>-0.041567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P2</th>\n",
       "      <td>0.010496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P4</th>\n",
       "      <td>0.038284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P6</th>\n",
       "      <td>0.081305</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P8</th>\n",
       "      <td>0.028134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">2023-11-30</th>\n",
       "      <th>P6</th>\n",
       "      <td>-0.012190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P7</th>\n",
       "      <td>-0.023572</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P8</th>\n",
       "      <td>-0.026295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P9</th>\n",
       "      <td>0.005428</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pmax</th>\n",
       "      <td>-0.050056</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3946 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        0\n",
       "month      sort          \n",
       "1991-01-31 P1   -0.041567\n",
       "           P2    0.010496\n",
       "           P4    0.038284\n",
       "           P6    0.081305\n",
       "           P8    0.028134\n",
       "...                   ...\n",
       "2023-11-30 P6   -0.012190\n",
       "           P7   -0.023572\n",
       "           P8   -0.026295\n",
       "           P9    0.005428\n",
       "           Pmax -0.050056\n",
       "\n",
       "[3946 rows x 1 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 短期动量策略\n",
    "portfolio_mom =  pd.DataFrame(\n",
    "    portfolio.groupby(['month','sort']).apply(lambda x: np.average(x['next_ret'],weights = x['floatingvalue']),include_groups=False))#分组\n",
    "portfolio_mom\n",
    "# 计算下一个月加权平均回报率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>sort</th>\n",
       "      <th>p</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1991-02-28</td>\n",
       "      <td>P1</td>\n",
       "      <td>-0.041567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1991-02-28</td>\n",
       "      <td>P2</td>\n",
       "      <td>0.010496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1991-02-28</td>\n",
       "      <td>P4</td>\n",
       "      <td>0.038284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1991-02-28</td>\n",
       "      <td>P6</td>\n",
       "      <td>0.081305</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1991-02-28</td>\n",
       "      <td>P8</td>\n",
       "      <td>0.028134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3941</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>P6</td>\n",
       "      <td>-0.012190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3942</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>P7</td>\n",
       "      <td>-0.023572</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3943</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>P8</td>\n",
       "      <td>-0.026295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3944</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>P9</td>\n",
       "      <td>0.005428</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3945</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>Pmax</td>\n",
       "      <td>-0.050056</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3946 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          month  sort         p\n",
       "0    1991-02-28    P1 -0.041567\n",
       "1    1991-02-28    P2  0.010496\n",
       "2    1991-02-28    P4  0.038284\n",
       "3    1991-02-28    P6  0.081305\n",
       "4    1991-02-28    P8  0.028134\n",
       "...         ...   ...       ...\n",
       "3941 2023-12-31    P6 -0.012190\n",
       "3942 2023-12-31    P7 -0.023572\n",
       "3943 2023-12-31    P8 -0.026295\n",
       "3944 2023-12-31    P9  0.005428\n",
       "3945 2023-12-31  Pmax -0.050056\n",
       "\n",
       "[3946 rows x 3 columns]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio_mom = portfolio_mom.reset_index()#去掉索引\n",
    "portfolio_mom.columns = ['month', 'sort', 'p']#改名\n",
    "portfolio_mom['month'] = portfolio_mom['month'] + MonthEnd(1)#月份加一\n",
    "portfolio_mom.dropna(subset=['p'],inplace=True)#去掉缺失值\n",
    "portfolio_mom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>sort</th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>Pmax</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1991-02-28</th>\n",
       "      <td>-0.041567</td>\n",
       "      <td>0.010496</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.038284</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.081305</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.028134</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.002070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-03-31</th>\n",
       "      <td>-0.133253</td>\n",
       "      <td>-0.069140</td>\n",
       "      <td>-0.133293</td>\n",
       "      <td>0.023904</td>\n",
       "      <td>-0.125264</td>\n",
       "      <td>0.070941</td>\n",
       "      <td>-0.133504</td>\n",
       "      <td>-0.044343</td>\n",
       "      <td>-0.070455</td>\n",
       "      <td>-0.059149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-04-30</th>\n",
       "      <td>-0.122736</td>\n",
       "      <td>-0.123391</td>\n",
       "      <td>-0.103582</td>\n",
       "      <td>-0.077512</td>\n",
       "      <td>-0.133193</td>\n",
       "      <td>-0.000595</td>\n",
       "      <td>0.070484</td>\n",
       "      <td>-0.097744</td>\n",
       "      <td>0.120035</td>\n",
       "      <td>0.087227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-31</th>\n",
       "      <td>-0.006657</td>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.130814</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.202117</td>\n",
       "      <td>0.238572</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-06-30</th>\n",
       "      <td>-0.093032</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.460637</td>\n",
       "      <td>-0.309901</td>\n",
       "      <td>0.190006</td>\n",
       "      <td>0.177858</td>\n",
       "      <td>0.213185</td>\n",
       "      <td>0.190283</td>\n",
       "      <td>0.166237</td>\n",
       "      <td>0.201980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.048515</td>\n",
       "      <td>-0.047374</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>-0.064861</td>\n",
       "      <td>-0.052590</td>\n",
       "      <td>-0.056458</td>\n",
       "      <td>-0.054358</td>\n",
       "      <td>-0.052533</td>\n",
       "      <td>-0.059833</td>\n",
       "      <td>-0.069041</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.013215</td>\n",
       "      <td>-0.008910</td>\n",
       "      <td>-0.008950</td>\n",
       "      <td>0.000798</td>\n",
       "      <td>0.000158</td>\n",
       "      <td>0.002106</td>\n",
       "      <td>0.001202</td>\n",
       "      <td>-0.024952</td>\n",
       "      <td>-0.007080</td>\n",
       "      <td>-0.012874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.068257</td>\n",
       "      <td>-0.026400</td>\n",
       "      <td>-0.026712</td>\n",
       "      <td>-0.035206</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.013751</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.033380</td>\n",
       "      <td>-0.029932</td>\n",
       "      <td>0.008262</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>0.005351</td>\n",
       "      <td>-0.021096</td>\n",
       "      <td>0.009551</td>\n",
       "      <td>-0.004467</td>\n",
       "      <td>0.005741</td>\n",
       "      <td>0.011742</td>\n",
       "      <td>-0.004673</td>\n",
       "      <td>-0.001100</td>\n",
       "      <td>0.010682</td>\n",
       "      <td>0.005062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.023762</td>\n",
       "      <td>-0.023652</td>\n",
       "      <td>-0.021338</td>\n",
       "      <td>-0.023467</td>\n",
       "      <td>-0.014802</td>\n",
       "      <td>-0.012190</td>\n",
       "      <td>-0.023572</td>\n",
       "      <td>-0.026295</td>\n",
       "      <td>0.005428</td>\n",
       "      <td>-0.050056</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>395 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "sort              P1        P2        P3        P4        P5        P6  \\\n",
       "month                                                                    \n",
       "1991-02-28 -0.041567  0.010496       NaN  0.038284       NaN  0.081305   \n",
       "1991-03-31 -0.133253 -0.069140 -0.133293  0.023904 -0.125264  0.070941   \n",
       "1991-04-30 -0.122736 -0.123391 -0.103582 -0.077512 -0.133193 -0.000595   \n",
       "1991-05-31 -0.006657 -0.129118 -0.036993 -0.120582 -0.130814 -0.031989   \n",
       "1991-06-30 -0.093032 -0.119551 -0.460637 -0.309901  0.190006  0.177858   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.048515 -0.047374 -0.049198 -0.064861 -0.052590 -0.056458   \n",
       "2023-09-30 -0.013215 -0.008910 -0.008950  0.000798  0.000158  0.002106   \n",
       "2023-10-31 -0.068257 -0.026400 -0.026712 -0.035206 -0.022298 -0.013751   \n",
       "2023-11-30  0.005351 -0.021096  0.009551 -0.004467  0.005741  0.011742   \n",
       "2023-12-31 -0.023762 -0.023652 -0.021338 -0.023467 -0.014802 -0.012190   \n",
       "\n",
       "sort              P7        P8        P9      Pmax  \n",
       "month                                               \n",
       "1991-02-28       NaN  0.028134       NaN -0.002070  \n",
       "1991-03-31 -0.133504 -0.044343 -0.070455 -0.059149  \n",
       "1991-04-30  0.070484 -0.097744  0.120035  0.087227  \n",
       "1991-05-31  0.080639  0.055289  0.202117  0.238572  \n",
       "1991-06-30  0.213185  0.190283  0.166237  0.201980  \n",
       "...              ...       ...       ...       ...  \n",
       "2023-08-31 -0.054358 -0.052533 -0.059833 -0.069041  \n",
       "2023-09-30  0.001202 -0.024952 -0.007080 -0.012874  \n",
       "2023-10-31 -0.022298 -0.033380 -0.029932  0.008262  \n",
       "2023-11-30 -0.004673 -0.001100  0.010682  0.005062  \n",
       "2023-12-31 -0.023572 -0.026295  0.005428 -0.050056  \n",
       "\n",
       "[395 rows x 10 columns]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio_mom = portfolio_mom.pivot_table(index='month',columns='sort',values='p')#变形\n",
    "portfolio_mom"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 我的策略"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>sort</th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>Pmax</th>\n",
       "      <th>My_portfolio</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1991-02-28</th>\n",
       "      <td>-0.041567</td>\n",
       "      <td>0.010496</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.038284</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.081305</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.028134</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.002070</td>\n",
       "      <td>-0.039497</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-03-31</th>\n",
       "      <td>-0.133253</td>\n",
       "      <td>-0.069140</td>\n",
       "      <td>-0.133293</td>\n",
       "      <td>0.023904</td>\n",
       "      <td>-0.125264</td>\n",
       "      <td>0.070941</td>\n",
       "      <td>-0.133504</td>\n",
       "      <td>-0.044343</td>\n",
       "      <td>-0.070455</td>\n",
       "      <td>-0.059149</td>\n",
       "      <td>-0.074104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-04-30</th>\n",
       "      <td>-0.122736</td>\n",
       "      <td>-0.123391</td>\n",
       "      <td>-0.103582</td>\n",
       "      <td>-0.077512</td>\n",
       "      <td>-0.133193</td>\n",
       "      <td>-0.000595</td>\n",
       "      <td>0.070484</td>\n",
       "      <td>-0.097744</td>\n",
       "      <td>0.120035</td>\n",
       "      <td>0.087227</td>\n",
       "      <td>-0.209963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-31</th>\n",
       "      <td>-0.006657</td>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.130814</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.202117</td>\n",
       "      <td>0.238572</td>\n",
       "      <td>-0.245229</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-06-30</th>\n",
       "      <td>-0.093032</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.460637</td>\n",
       "      <td>-0.309901</td>\n",
       "      <td>0.190006</td>\n",
       "      <td>0.177858</td>\n",
       "      <td>0.213185</td>\n",
       "      <td>0.190283</td>\n",
       "      <td>0.166237</td>\n",
       "      <td>0.201980</td>\n",
       "      <td>-0.295012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.048515</td>\n",
       "      <td>-0.047374</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>-0.064861</td>\n",
       "      <td>-0.052590</td>\n",
       "      <td>-0.056458</td>\n",
       "      <td>-0.054358</td>\n",
       "      <td>-0.052533</td>\n",
       "      <td>-0.059833</td>\n",
       "      <td>-0.069041</td>\n",
       "      <td>0.020526</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.013215</td>\n",
       "      <td>-0.008910</td>\n",
       "      <td>-0.008950</td>\n",
       "      <td>0.000798</td>\n",
       "      <td>0.000158</td>\n",
       "      <td>0.002106</td>\n",
       "      <td>0.001202</td>\n",
       "      <td>-0.024952</td>\n",
       "      <td>-0.007080</td>\n",
       "      <td>-0.012874</td>\n",
       "      <td>-0.000340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.068257</td>\n",
       "      <td>-0.026400</td>\n",
       "      <td>-0.026712</td>\n",
       "      <td>-0.035206</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.013751</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.033380</td>\n",
       "      <td>-0.029932</td>\n",
       "      <td>0.008262</td>\n",
       "      <td>-0.076519</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>0.005351</td>\n",
       "      <td>-0.021096</td>\n",
       "      <td>0.009551</td>\n",
       "      <td>-0.004467</td>\n",
       "      <td>0.005741</td>\n",
       "      <td>0.011742</td>\n",
       "      <td>-0.004673</td>\n",
       "      <td>-0.001100</td>\n",
       "      <td>0.010682</td>\n",
       "      <td>0.005062</td>\n",
       "      <td>0.000289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.023762</td>\n",
       "      <td>-0.023652</td>\n",
       "      <td>-0.021338</td>\n",
       "      <td>-0.023467</td>\n",
       "      <td>-0.014802</td>\n",
       "      <td>-0.012190</td>\n",
       "      <td>-0.023572</td>\n",
       "      <td>-0.026295</td>\n",
       "      <td>0.005428</td>\n",
       "      <td>-0.050056</td>\n",
       "      <td>0.026293</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>395 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "sort              P1        P2        P3        P4        P5        P6  \\\n",
       "month                                                                    \n",
       "1991-02-28 -0.041567  0.010496       NaN  0.038284       NaN  0.081305   \n",
       "1991-03-31 -0.133253 -0.069140 -0.133293  0.023904 -0.125264  0.070941   \n",
       "1991-04-30 -0.122736 -0.123391 -0.103582 -0.077512 -0.133193 -0.000595   \n",
       "1991-05-31 -0.006657 -0.129118 -0.036993 -0.120582 -0.130814 -0.031989   \n",
       "1991-06-30 -0.093032 -0.119551 -0.460637 -0.309901  0.190006  0.177858   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.048515 -0.047374 -0.049198 -0.064861 -0.052590 -0.056458   \n",
       "2023-09-30 -0.013215 -0.008910 -0.008950  0.000798  0.000158  0.002106   \n",
       "2023-10-31 -0.068257 -0.026400 -0.026712 -0.035206 -0.022298 -0.013751   \n",
       "2023-11-30  0.005351 -0.021096  0.009551 -0.004467  0.005741  0.011742   \n",
       "2023-12-31 -0.023762 -0.023652 -0.021338 -0.023467 -0.014802 -0.012190   \n",
       "\n",
       "sort              P7        P8        P9      Pmax  My_portfolio  \n",
       "month                                                             \n",
       "1991-02-28       NaN  0.028134       NaN -0.002070     -0.039497  \n",
       "1991-03-31 -0.133504 -0.044343 -0.070455 -0.059149     -0.074104  \n",
       "1991-04-30  0.070484 -0.097744  0.120035  0.087227     -0.209963  \n",
       "1991-05-31  0.080639  0.055289  0.202117  0.238572     -0.245229  \n",
       "1991-06-30  0.213185  0.190283  0.166237  0.201980     -0.295012  \n",
       "...              ...       ...       ...       ...           ...  \n",
       "2023-08-31 -0.054358 -0.052533 -0.059833 -0.069041      0.020526  \n",
       "2023-09-30  0.001202 -0.024952 -0.007080 -0.012874     -0.000340  \n",
       "2023-10-31 -0.022298 -0.033380 -0.029932  0.008262     -0.076519  \n",
       "2023-11-30 -0.004673 -0.001100  0.010682  0.005062      0.000289  \n",
       "2023-12-31 -0.023572 -0.026295  0.005428 -0.050056      0.026293  \n",
       "\n",
       "[395 rows x 11 columns]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio_mom['My_portfolio'] = portfolio_mom['P1'] - portfolio_mom['Pmax']#买涨的最多的，卖涨的最低的\n",
    "portfolio_mom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>sort</th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>Pmax</th>\n",
       "      <th>My_portfolio</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000-01-31</th>\n",
       "      <td>0.128892</td>\n",
       "      <td>0.125095</td>\n",
       "      <td>0.109649</td>\n",
       "      <td>0.164682</td>\n",
       "      <td>0.134155</td>\n",
       "      <td>0.117154</td>\n",
       "      <td>0.154231</td>\n",
       "      <td>0.133388</td>\n",
       "      <td>0.189671</td>\n",
       "      <td>0.277708</td>\n",
       "      <td>-0.148816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-02-29</th>\n",
       "      <td>0.148460</td>\n",
       "      <td>0.098851</td>\n",
       "      <td>0.122838</td>\n",
       "      <td>0.084378</td>\n",
       "      <td>0.193957</td>\n",
       "      <td>0.095636</td>\n",
       "      <td>0.080466</td>\n",
       "      <td>0.102473</td>\n",
       "      <td>0.169644</td>\n",
       "      <td>0.125983</td>\n",
       "      <td>0.022476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-03-31</th>\n",
       "      <td>0.028538</td>\n",
       "      <td>0.056167</td>\n",
       "      <td>0.088460</td>\n",
       "      <td>0.093958</td>\n",
       "      <td>0.115092</td>\n",
       "      <td>0.082248</td>\n",
       "      <td>0.079722</td>\n",
       "      <td>0.081513</td>\n",
       "      <td>0.040770</td>\n",
       "      <td>-0.044828</td>\n",
       "      <td>0.073366</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-04-30</th>\n",
       "      <td>-0.005793</td>\n",
       "      <td>0.018555</td>\n",
       "      <td>0.037055</td>\n",
       "      <td>0.023933</td>\n",
       "      <td>0.009921</td>\n",
       "      <td>0.018328</td>\n",
       "      <td>0.021396</td>\n",
       "      <td>0.004873</td>\n",
       "      <td>-0.011356</td>\n",
       "      <td>-0.015714</td>\n",
       "      <td>0.009921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-05-31</th>\n",
       "      <td>0.019856</td>\n",
       "      <td>0.013618</td>\n",
       "      <td>0.007191</td>\n",
       "      <td>0.016574</td>\n",
       "      <td>0.034658</td>\n",
       "      <td>0.026428</td>\n",
       "      <td>0.025010</td>\n",
       "      <td>0.058083</td>\n",
       "      <td>0.021637</td>\n",
       "      <td>0.036778</td>\n",
       "      <td>-0.016922</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.048515</td>\n",
       "      <td>-0.047374</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>-0.064861</td>\n",
       "      <td>-0.052590</td>\n",
       "      <td>-0.056458</td>\n",
       "      <td>-0.054358</td>\n",
       "      <td>-0.052533</td>\n",
       "      <td>-0.059833</td>\n",
       "      <td>-0.069041</td>\n",
       "      <td>0.020526</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.013215</td>\n",
       "      <td>-0.008910</td>\n",
       "      <td>-0.008950</td>\n",
       "      <td>0.000798</td>\n",
       "      <td>0.000158</td>\n",
       "      <td>0.002106</td>\n",
       "      <td>0.001202</td>\n",
       "      <td>-0.024952</td>\n",
       "      <td>-0.007080</td>\n",
       "      <td>-0.012874</td>\n",
       "      <td>-0.000340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.068257</td>\n",
       "      <td>-0.026400</td>\n",
       "      <td>-0.026712</td>\n",
       "      <td>-0.035206</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.013751</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.033380</td>\n",
       "      <td>-0.029932</td>\n",
       "      <td>0.008262</td>\n",
       "      <td>-0.076519</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>0.005351</td>\n",
       "      <td>-0.021096</td>\n",
       "      <td>0.009551</td>\n",
       "      <td>-0.004467</td>\n",
       "      <td>0.005741</td>\n",
       "      <td>0.011742</td>\n",
       "      <td>-0.004673</td>\n",
       "      <td>-0.001100</td>\n",
       "      <td>0.010682</td>\n",
       "      <td>0.005062</td>\n",
       "      <td>0.000289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.023762</td>\n",
       "      <td>-0.023652</td>\n",
       "      <td>-0.021338</td>\n",
       "      <td>-0.023467</td>\n",
       "      <td>-0.014802</td>\n",
       "      <td>-0.012190</td>\n",
       "      <td>-0.023572</td>\n",
       "      <td>-0.026295</td>\n",
       "      <td>0.005428</td>\n",
       "      <td>-0.050056</td>\n",
       "      <td>0.026293</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>288 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "sort              P1        P2        P3        P4        P5        P6  \\\n",
       "month                                                                    \n",
       "2000-01-31  0.128892  0.125095  0.109649  0.164682  0.134155  0.117154   \n",
       "2000-02-29  0.148460  0.098851  0.122838  0.084378  0.193957  0.095636   \n",
       "2000-03-31  0.028538  0.056167  0.088460  0.093958  0.115092  0.082248   \n",
       "2000-04-30 -0.005793  0.018555  0.037055  0.023933  0.009921  0.018328   \n",
       "2000-05-31  0.019856  0.013618  0.007191  0.016574  0.034658  0.026428   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.048515 -0.047374 -0.049198 -0.064861 -0.052590 -0.056458   \n",
       "2023-09-30 -0.013215 -0.008910 -0.008950  0.000798  0.000158  0.002106   \n",
       "2023-10-31 -0.068257 -0.026400 -0.026712 -0.035206 -0.022298 -0.013751   \n",
       "2023-11-30  0.005351 -0.021096  0.009551 -0.004467  0.005741  0.011742   \n",
       "2023-12-31 -0.023762 -0.023652 -0.021338 -0.023467 -0.014802 -0.012190   \n",
       "\n",
       "sort              P7        P8        P9      Pmax  My_portfolio  \n",
       "month                                                             \n",
       "2000-01-31  0.154231  0.133388  0.189671  0.277708     -0.148816  \n",
       "2000-02-29  0.080466  0.102473  0.169644  0.125983      0.022476  \n",
       "2000-03-31  0.079722  0.081513  0.040770 -0.044828      0.073366  \n",
       "2000-04-30  0.021396  0.004873 -0.011356 -0.015714      0.009921  \n",
       "2000-05-31  0.025010  0.058083  0.021637  0.036778     -0.016922  \n",
       "...              ...       ...       ...       ...           ...  \n",
       "2023-08-31 -0.054358 -0.052533 -0.059833 -0.069041      0.020526  \n",
       "2023-09-30  0.001202 -0.024952 -0.007080 -0.012874     -0.000340  \n",
       "2023-10-31 -0.022298 -0.033380 -0.029932  0.008262     -0.076519  \n",
       "2023-11-30 -0.004673 -0.001100  0.010682  0.005062      0.000289  \n",
       "2023-12-31 -0.023572 -0.026295  0.005428 -0.050056      0.026293  \n",
       "\n",
       "[288 rows x 11 columns]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio_mom = portfolio_mom['2000':]#不考虑早期\n",
    "portfolio_mom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:           My_portfolio   R-squared:                       0.000\n",
      "Model:                            OLS   Adj. R-squared:                  0.000\n",
      "Method:                 Least Squares   F-statistic:                       nan\n",
      "Date:                Sat, 30 Nov 2024   Prob (F-statistic):                nan\n",
      "Time:                        23:56:05   Log-Likelihood:                 368.99\n",
      "No. Observations:                 287   AIC:                            -736.0\n",
      "Df Residuals:                     286   BIC:                            -732.3\n",
      "Df Model:                           0                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0094      0.004      2.527      0.012       0.002       0.017\n",
      "==============================================================================\n",
      "Omnibus:                       30.518   Durbin-Watson:                   2.082\n",
      "Prob(Omnibus):                  0.000   Jarque-Bera (JB):              140.360\n",
      "Skew:                          -0.202   Prob(JB):                     3.32e-31\n",
      "Kurtosis:                       6.402   Cond. No.                         1.00\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 6 lags and without small sample correction\n"
     ]
    }
   ],
   "source": [
    "model_port = smf.ols('My_portfolio ~ 1',data=portfolio_mom['2000-02':'2023-12']).fit(\n",
    "    cov_type='HAC', cov_kwds={'maxlags': 6})\n",
    "print(model_port.summary())\n",
    "# 回归的结果和直接做均值t检验的结果是一样的"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Adj.R-squared为0是正常的，因为1是常数\n",
    "\n",
    "该投资组合平均每月赚0.94%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Money</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Day</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1990-12-19</th>\n",
       "      <td></td>\n",
       "      <td>96.050</td>\n",
       "      <td>99.980</td>\n",
       "      <td>95.790</td>\n",
       "      <td>99.980</td>\n",
       "      <td>126000.00</td>\n",
       "      <td>4.940000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-20</th>\n",
       "      <td>99.98</td>\n",
       "      <td>104.300</td>\n",
       "      <td>104.390</td>\n",
       "      <td>99.980</td>\n",
       "      <td>104.390</td>\n",
       "      <td>19700.00</td>\n",
       "      <td>8.400000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-21</th>\n",
       "      <td>104.39</td>\n",
       "      <td>109.070</td>\n",
       "      <td>109.130</td>\n",
       "      <td>103.730</td>\n",
       "      <td>109.130</td>\n",
       "      <td>2800.00</td>\n",
       "      <td>1.600000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-24</th>\n",
       "      <td>109.13</td>\n",
       "      <td>113.570</td>\n",
       "      <td>114.550</td>\n",
       "      <td>109.130</td>\n",
       "      <td>114.550</td>\n",
       "      <td>3200.00</td>\n",
       "      <td>3.100000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-25</th>\n",
       "      <td>114.55</td>\n",
       "      <td>120.090</td>\n",
       "      <td>120.250</td>\n",
       "      <td>114.550</td>\n",
       "      <td>120.250</td>\n",
       "      <td>1500.00</td>\n",
       "      <td>6.000000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-24</th>\n",
       "      <td>2748.918</td>\n",
       "      <td>2770.754</td>\n",
       "      <td>2863.152</td>\n",
       "      <td>2761.372</td>\n",
       "      <td>2863.126</td>\n",
       "      <td>4776195.45</td>\n",
       "      <td>4.427953e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-25</th>\n",
       "      <td>2863.126</td>\n",
       "      <td>2901.419</td>\n",
       "      <td>2952.451</td>\n",
       "      <td>2889.048</td>\n",
       "      <td>2896.306</td>\n",
       "      <td>5682598.16</td>\n",
       "      <td>5.166981e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-26</th>\n",
       "      <td>2896.306</td>\n",
       "      <td>2893.745</td>\n",
       "      <td>3000.953</td>\n",
       "      <td>2889.014</td>\n",
       "      <td>3000.953</td>\n",
       "      <td>5763192.61</td>\n",
       "      <td>5.246691e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-27</th>\n",
       "      <td>3000.953</td>\n",
       "      <td>3049.103</td>\n",
       "      <td>3087.529</td>\n",
       "      <td>3017.445</td>\n",
       "      <td>3087.529</td>\n",
       "      <td>4922871.63</td>\n",
       "      <td>4.806126e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>3087.529</td>\n",
       "      <td>3194.722</td>\n",
       "      <td>3358.588</td>\n",
       "      <td>3153.697</td>\n",
       "      <td>3336.497</td>\n",
       "      <td>11023379.17</td>\n",
       "      <td>1.167773e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8251 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Preclose      Open   Highest    Lowest     Close       Volume  \\\n",
       "Day                                                                         \n",
       "1990-12-19              96.050    99.980    95.790    99.980    126000.00   \n",
       "1990-12-20     99.98   104.300   104.390    99.980   104.390     19700.00   \n",
       "1990-12-21    104.39   109.070   109.130   103.730   109.130      2800.00   \n",
       "1990-12-24    109.13   113.570   114.550   109.130   114.550      3200.00   \n",
       "1990-12-25    114.55   120.090   120.250   114.550   120.250      1500.00   \n",
       "...              ...       ...       ...       ...       ...          ...   \n",
       "2024-09-24  2748.918  2770.754  2863.152  2761.372  2863.126   4776195.45   \n",
       "2024-09-25  2863.126  2901.419  2952.451  2889.048  2896.306   5682598.16   \n",
       "2024-09-26  2896.306  2893.745  3000.953  2889.014  3000.953   5763192.61   \n",
       "2024-09-27  3000.953  3049.103  3087.529  3017.445  3087.529   4922871.63   \n",
       "2024-09-30  3087.529  3194.722  3358.588  3153.697  3336.497  11023379.17   \n",
       "\n",
       "                   Money  \n",
       "Day                       \n",
       "1990-12-19  4.940000e+05  \n",
       "1990-12-20  8.400000e+04  \n",
       "1990-12-21  1.600000e+04  \n",
       "1990-12-24  3.100000e+04  \n",
       "1990-12-25  6.000000e+03  \n",
       "...                  ...  \n",
       "2024-09-24  4.427953e+07  \n",
       "2024-09-25  5.166981e+07  \n",
       "2024-09-26  5.246691e+07  \n",
       "2024-09-27  4.806126e+07  \n",
       "2024-09-30  1.167773e+08  \n",
       "\n",
       "[8251 rows x 7 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Raw_return</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1995-01-31</th>\n",
       "      <td>-0.131631</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-02-28</th>\n",
       "      <td>-0.023694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-03-31</th>\n",
       "      <td>0.177803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-04-30</th>\n",
       "      <td>-0.103552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-05-31</th>\n",
       "      <td>0.207922</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-05-31</th>\n",
       "      <td>-0.005801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-30</th>\n",
       "      <td>-0.038684</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-31</th>\n",
       "      <td>-0.009656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-08-31</th>\n",
       "      <td>-0.032849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>0.173908</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>357 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Raw_return\n",
       "month                 \n",
       "1995-01-31   -0.131631\n",
       "1995-02-28   -0.023694\n",
       "1995-03-31    0.177803\n",
       "1995-04-30   -0.103552\n",
       "1995-05-31    0.207922\n",
       "...                ...\n",
       "2024-05-31   -0.005801\n",
       "2024-06-30   -0.038684\n",
       "2024-07-31   -0.009656\n",
       "2024-08-31   -0.032849\n",
       "2024-09-30    0.173908\n",
       "\n",
       "[357 rows x 1 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv(\"D:/python-homework/python-homework/000001.csv\")#导入数据\n",
    "data['Day'] = pd.to_datetime(data['Day'],format='%Y/%m/%d')#变成时间格式\n",
    "data.set_index('Day', inplace = True)#生成索引\n",
    "data.sort_values(by = ['Day'],axis=0, ascending=True)#升序排序\n",
    "data_new = data['1995-01':'2024-09'].copy()#用copy来进行深度复制\n",
    "data_new['Close'] = pd.to_numeric(data_new['Close'])#变成数值型\n",
    "data_new['Preclose'] = pd.to_numeric(data_new['Preclose'])#变成数值型\n",
    "data_new['Raw_return'] = data_new['Close'] / data_new['Preclose'] - 1\n",
    "Month_data = data_new.resample('ME')['Raw_return'].apply(lambda x: (1+x).prod() - 1).to_frame()#计算回报率\n",
    "Month_data.reset_index(inplace = True)#去掉索引\n",
    "Month_data.rename(columns = {'Day':'month'}, inplace = True)#重命名\n",
    "Month_data.set_index('month', inplace = True)#索引\n",
    "Month_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 什么是$\\beta$和$\\alpha$\n",
    "先有$\\beta$再有$\\alpha$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>Pmax</th>\n",
       "      <th>My_portfolio</th>\n",
       "      <th>Raw_return</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000-01-31</th>\n",
       "      <td>0.128892</td>\n",
       "      <td>0.125095</td>\n",
       "      <td>0.109649</td>\n",
       "      <td>0.164682</td>\n",
       "      <td>0.134155</td>\n",
       "      <td>0.117154</td>\n",
       "      <td>0.154231</td>\n",
       "      <td>0.133388</td>\n",
       "      <td>0.189671</td>\n",
       "      <td>0.277708</td>\n",
       "      <td>-0.148816</td>\n",
       "      <td>0.123242</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-02-29</th>\n",
       "      <td>0.148460</td>\n",
       "      <td>0.098851</td>\n",
       "      <td>0.122838</td>\n",
       "      <td>0.084378</td>\n",
       "      <td>0.193957</td>\n",
       "      <td>0.095636</td>\n",
       "      <td>0.080466</td>\n",
       "      <td>0.102473</td>\n",
       "      <td>0.169644</td>\n",
       "      <td>0.125983</td>\n",
       "      <td>0.022476</td>\n",
       "      <td>0.116990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-03-31</th>\n",
       "      <td>0.028538</td>\n",
       "      <td>0.056167</td>\n",
       "      <td>0.088460</td>\n",
       "      <td>0.093958</td>\n",
       "      <td>0.115092</td>\n",
       "      <td>0.082248</td>\n",
       "      <td>0.079722</td>\n",
       "      <td>0.081513</td>\n",
       "      <td>0.040770</td>\n",
       "      <td>-0.044828</td>\n",
       "      <td>0.073366</td>\n",
       "      <td>0.049948</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-04-30</th>\n",
       "      <td>-0.005793</td>\n",
       "      <td>0.018555</td>\n",
       "      <td>0.037055</td>\n",
       "      <td>0.023933</td>\n",
       "      <td>0.009921</td>\n",
       "      <td>0.018328</td>\n",
       "      <td>0.021396</td>\n",
       "      <td>0.004873</td>\n",
       "      <td>-0.011356</td>\n",
       "      <td>-0.015714</td>\n",
       "      <td>0.009921</td>\n",
       "      <td>0.020053</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-05-31</th>\n",
       "      <td>0.019856</td>\n",
       "      <td>0.013618</td>\n",
       "      <td>0.007191</td>\n",
       "      <td>0.016574</td>\n",
       "      <td>0.034658</td>\n",
       "      <td>0.026428</td>\n",
       "      <td>0.025010</td>\n",
       "      <td>0.058083</td>\n",
       "      <td>0.021637</td>\n",
       "      <td>0.036778</td>\n",
       "      <td>-0.016922</td>\n",
       "      <td>0.031710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.048515</td>\n",
       "      <td>-0.047374</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>-0.064861</td>\n",
       "      <td>-0.052590</td>\n",
       "      <td>-0.056458</td>\n",
       "      <td>-0.054358</td>\n",
       "      <td>-0.052533</td>\n",
       "      <td>-0.059833</td>\n",
       "      <td>-0.069041</td>\n",
       "      <td>0.020526</td>\n",
       "      <td>-0.052009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.013215</td>\n",
       "      <td>-0.008910</td>\n",
       "      <td>-0.008950</td>\n",
       "      <td>0.000798</td>\n",
       "      <td>0.000158</td>\n",
       "      <td>0.002106</td>\n",
       "      <td>0.001202</td>\n",
       "      <td>-0.024952</td>\n",
       "      <td>-0.007080</td>\n",
       "      <td>-0.012874</td>\n",
       "      <td>-0.000340</td>\n",
       "      <td>-0.003013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.068257</td>\n",
       "      <td>-0.026400</td>\n",
       "      <td>-0.026712</td>\n",
       "      <td>-0.035206</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.013751</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.033380</td>\n",
       "      <td>-0.029932</td>\n",
       "      <td>0.008262</td>\n",
       "      <td>-0.076519</td>\n",
       "      <td>-0.029483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>0.005351</td>\n",
       "      <td>-0.021096</td>\n",
       "      <td>0.009551</td>\n",
       "      <td>-0.004467</td>\n",
       "      <td>0.005741</td>\n",
       "      <td>0.011742</td>\n",
       "      <td>-0.004673</td>\n",
       "      <td>-0.001100</td>\n",
       "      <td>0.010682</td>\n",
       "      <td>0.005062</td>\n",
       "      <td>0.000289</td>\n",
       "      <td>0.003611</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.023762</td>\n",
       "      <td>-0.023652</td>\n",
       "      <td>-0.021338</td>\n",
       "      <td>-0.023467</td>\n",
       "      <td>-0.014802</td>\n",
       "      <td>-0.012190</td>\n",
       "      <td>-0.023572</td>\n",
       "      <td>-0.026295</td>\n",
       "      <td>0.005428</td>\n",
       "      <td>-0.050056</td>\n",
       "      <td>0.026293</td>\n",
       "      <td>-0.018067</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>288 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  P1        P2        P3        P4        P5        P6  \\\n",
       "month                                                                    \n",
       "2000-01-31  0.128892  0.125095  0.109649  0.164682  0.134155  0.117154   \n",
       "2000-02-29  0.148460  0.098851  0.122838  0.084378  0.193957  0.095636   \n",
       "2000-03-31  0.028538  0.056167  0.088460  0.093958  0.115092  0.082248   \n",
       "2000-04-30 -0.005793  0.018555  0.037055  0.023933  0.009921  0.018328   \n",
       "2000-05-31  0.019856  0.013618  0.007191  0.016574  0.034658  0.026428   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.048515 -0.047374 -0.049198 -0.064861 -0.052590 -0.056458   \n",
       "2023-09-30 -0.013215 -0.008910 -0.008950  0.000798  0.000158  0.002106   \n",
       "2023-10-31 -0.068257 -0.026400 -0.026712 -0.035206 -0.022298 -0.013751   \n",
       "2023-11-30  0.005351 -0.021096  0.009551 -0.004467  0.005741  0.011742   \n",
       "2023-12-31 -0.023762 -0.023652 -0.021338 -0.023467 -0.014802 -0.012190   \n",
       "\n",
       "                  P7        P8        P9      Pmax  My_portfolio  Raw_return  \n",
       "month                                                                         \n",
       "2000-01-31  0.154231  0.133388  0.189671  0.277708     -0.148816    0.123242  \n",
       "2000-02-29  0.080466  0.102473  0.169644  0.125983      0.022476    0.116990  \n",
       "2000-03-31  0.079722  0.081513  0.040770 -0.044828      0.073366    0.049948  \n",
       "2000-04-30  0.021396  0.004873 -0.011356 -0.015714      0.009921    0.020053  \n",
       "2000-05-31  0.025010  0.058083  0.021637  0.036778     -0.016922    0.031710  \n",
       "...              ...       ...       ...       ...           ...         ...  \n",
       "2023-08-31 -0.054358 -0.052533 -0.059833 -0.069041      0.020526   -0.052009  \n",
       "2023-09-30  0.001202 -0.024952 -0.007080 -0.012874     -0.000340   -0.003013  \n",
       "2023-10-31 -0.022298 -0.033380 -0.029932  0.008262     -0.076519   -0.029483  \n",
       "2023-11-30 -0.004673 -0.001100  0.010682  0.005062      0.000289    0.003611  \n",
       "2023-12-31 -0.023572 -0.026295  0.005428 -0.050056      0.026293   -0.018067  \n",
       "\n",
       "[288 rows x 12 columns]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MYPORT = pd.merge(portfolio_mom,Month_data,how='left',on='month')\n",
    "MYPORT\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:           My_portfolio   R-squared:                       0.011\n",
      "Model:                            OLS   Adj. R-squared:                  0.008\n",
      "Method:                 Least Squares   F-statistic:                     1.134\n",
      "Date:                Sat, 30 Nov 2024   Prob (F-statistic):              0.288\n",
      "Time:                        23:56:05   Log-Likelihood:                 369.66\n",
      "No. Observations:                 288   AIC:                            -735.3\n",
      "Df Residuals:                     286   BIC:                            -728.0\n",
      "Df Model:                           1                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0094      0.003      2.712      0.007       0.003       0.016\n",
      "Raw_return    -0.1021      0.096     -1.065      0.287      -0.290       0.086\n",
      "==============================================================================\n",
      "Omnibus:                       23.243   Durbin-Watson:                   2.109\n",
      "Prob(Omnibus):                  0.000   Jarque-Bera (JB):               88.765\n",
      "Skew:                          -0.050   Prob(JB):                     5.31e-20\n",
      "Kurtosis:                       5.718   Cond. No.                         14.1\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 6 lags and without small sample correction\n"
     ]
    }
   ],
   "source": [
    "#把我们的收益率回归到大盘上去\n",
    "model_port = smf.ols('My_portfolio ~ Raw_return',data=MYPORT['2000-01':'2023-12']).fit(\n",
    "    cov_type='HAC', cov_kwds={'maxlags': 6})\n",
    "print(model_port.summary())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "R_{mom,t} = 0.0094-0.1021*R_{m,t}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- $\\beta$是负的，而且不显著，说明我的策略和大盘无关，我的策略不是$\\beta$策略\n",
    "- $\\alpha$是正的，而且在1\\%置信水平显著，说明我的策略是纯粹的$\\alpha$策略\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 策略的价格变动"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>Pmax</th>\n",
       "      <th>My_portfolio</th>\n",
       "      <th>Raw_return</th>\n",
       "      <th>price_portfolio</th>\n",
       "      <th>P1_price</th>\n",
       "      <th>Pmax_price</th>\n",
       "      <th>Market_price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000-01-31</th>\n",
       "      <td>0.128892</td>\n",
       "      <td>0.125095</td>\n",
       "      <td>0.109649</td>\n",
       "      <td>0.164682</td>\n",
       "      <td>0.134155</td>\n",
       "      <td>0.117154</td>\n",
       "      <td>0.154231</td>\n",
       "      <td>0.133388</td>\n",
       "      <td>0.189671</td>\n",
       "      <td>0.277708</td>\n",
       "      <td>-0.148816</td>\n",
       "      <td>0.123242</td>\n",
       "      <td>0.851184</td>\n",
       "      <td>1.128892</td>\n",
       "      <td>1.277708</td>\n",
       "      <td>1.123242</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-02-29</th>\n",
       "      <td>0.148460</td>\n",
       "      <td>0.098851</td>\n",
       "      <td>0.122838</td>\n",
       "      <td>0.084378</td>\n",
       "      <td>0.193957</td>\n",
       "      <td>0.095636</td>\n",
       "      <td>0.080466</td>\n",
       "      <td>0.102473</td>\n",
       "      <td>0.169644</td>\n",
       "      <td>0.125983</td>\n",
       "      <td>0.022476</td>\n",
       "      <td>0.116990</td>\n",
       "      <td>0.870316</td>\n",
       "      <td>1.296487</td>\n",
       "      <td>1.438677</td>\n",
       "      <td>1.254650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-03-31</th>\n",
       "      <td>0.028538</td>\n",
       "      <td>0.056167</td>\n",
       "      <td>0.088460</td>\n",
       "      <td>0.093958</td>\n",
       "      <td>0.115092</td>\n",
       "      <td>0.082248</td>\n",
       "      <td>0.079722</td>\n",
       "      <td>0.081513</td>\n",
       "      <td>0.040770</td>\n",
       "      <td>-0.044828</td>\n",
       "      <td>0.073366</td>\n",
       "      <td>0.049948</td>\n",
       "      <td>0.934168</td>\n",
       "      <td>1.333486</td>\n",
       "      <td>1.374184</td>\n",
       "      <td>1.317318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-04-30</th>\n",
       "      <td>-0.005793</td>\n",
       "      <td>0.018555</td>\n",
       "      <td>0.037055</td>\n",
       "      <td>0.023933</td>\n",
       "      <td>0.009921</td>\n",
       "      <td>0.018328</td>\n",
       "      <td>0.021396</td>\n",
       "      <td>0.004873</td>\n",
       "      <td>-0.011356</td>\n",
       "      <td>-0.015714</td>\n",
       "      <td>0.009921</td>\n",
       "      <td>0.020053</td>\n",
       "      <td>0.943436</td>\n",
       "      <td>1.325762</td>\n",
       "      <td>1.352590</td>\n",
       "      <td>1.343734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-05-31</th>\n",
       "      <td>0.019856</td>\n",
       "      <td>0.013618</td>\n",
       "      <td>0.007191</td>\n",
       "      <td>0.016574</td>\n",
       "      <td>0.034658</td>\n",
       "      <td>0.026428</td>\n",
       "      <td>0.025010</td>\n",
       "      <td>0.058083</td>\n",
       "      <td>0.021637</td>\n",
       "      <td>0.036778</td>\n",
       "      <td>-0.016922</td>\n",
       "      <td>0.031710</td>\n",
       "      <td>0.927471</td>\n",
       "      <td>1.352086</td>\n",
       "      <td>1.402335</td>\n",
       "      <td>1.386344</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.048515</td>\n",
       "      <td>-0.047374</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>-0.064861</td>\n",
       "      <td>-0.052590</td>\n",
       "      <td>-0.056458</td>\n",
       "      <td>-0.054358</td>\n",
       "      <td>-0.052533</td>\n",
       "      <td>-0.059833</td>\n",
       "      <td>-0.069041</td>\n",
       "      <td>0.020526</td>\n",
       "      <td>-0.052009</td>\n",
       "      <td>6.946370</td>\n",
       "      <td>4.670596</td>\n",
       "      <td>0.316197</td>\n",
       "      <td>2.282984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.013215</td>\n",
       "      <td>-0.008910</td>\n",
       "      <td>-0.008950</td>\n",
       "      <td>0.000798</td>\n",
       "      <td>0.000158</td>\n",
       "      <td>0.002106</td>\n",
       "      <td>0.001202</td>\n",
       "      <td>-0.024952</td>\n",
       "      <td>-0.007080</td>\n",
       "      <td>-0.012874</td>\n",
       "      <td>-0.000340</td>\n",
       "      <td>-0.003013</td>\n",
       "      <td>6.944005</td>\n",
       "      <td>4.608875</td>\n",
       "      <td>0.312126</td>\n",
       "      <td>2.276105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.068257</td>\n",
       "      <td>-0.026400</td>\n",
       "      <td>-0.026712</td>\n",
       "      <td>-0.035206</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.013751</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.033380</td>\n",
       "      <td>-0.029932</td>\n",
       "      <td>0.008262</td>\n",
       "      <td>-0.076519</td>\n",
       "      <td>-0.029483</td>\n",
       "      <td>6.412660</td>\n",
       "      <td>4.294287</td>\n",
       "      <td>0.314704</td>\n",
       "      <td>2.208999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>0.005351</td>\n",
       "      <td>-0.021096</td>\n",
       "      <td>0.009551</td>\n",
       "      <td>-0.004467</td>\n",
       "      <td>0.005741</td>\n",
       "      <td>0.011742</td>\n",
       "      <td>-0.004673</td>\n",
       "      <td>-0.001100</td>\n",
       "      <td>0.010682</td>\n",
       "      <td>0.005062</td>\n",
       "      <td>0.000289</td>\n",
       "      <td>0.003611</td>\n",
       "      <td>6.414512</td>\n",
       "      <td>4.317264</td>\n",
       "      <td>0.316297</td>\n",
       "      <td>2.216977</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.023762</td>\n",
       "      <td>-0.023652</td>\n",
       "      <td>-0.021338</td>\n",
       "      <td>-0.023467</td>\n",
       "      <td>-0.014802</td>\n",
       "      <td>-0.012190</td>\n",
       "      <td>-0.023572</td>\n",
       "      <td>-0.026295</td>\n",
       "      <td>0.005428</td>\n",
       "      <td>-0.050056</td>\n",
       "      <td>0.026293</td>\n",
       "      <td>-0.018067</td>\n",
       "      <td>6.583172</td>\n",
       "      <td>4.214677</td>\n",
       "      <td>0.300465</td>\n",
       "      <td>2.176922</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>288 rows × 16 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  P1        P2        P3        P4        P5        P6  \\\n",
       "month                                                                    \n",
       "2000-01-31  0.128892  0.125095  0.109649  0.164682  0.134155  0.117154   \n",
       "2000-02-29  0.148460  0.098851  0.122838  0.084378  0.193957  0.095636   \n",
       "2000-03-31  0.028538  0.056167  0.088460  0.093958  0.115092  0.082248   \n",
       "2000-04-30 -0.005793  0.018555  0.037055  0.023933  0.009921  0.018328   \n",
       "2000-05-31  0.019856  0.013618  0.007191  0.016574  0.034658  0.026428   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.048515 -0.047374 -0.049198 -0.064861 -0.052590 -0.056458   \n",
       "2023-09-30 -0.013215 -0.008910 -0.008950  0.000798  0.000158  0.002106   \n",
       "2023-10-31 -0.068257 -0.026400 -0.026712 -0.035206 -0.022298 -0.013751   \n",
       "2023-11-30  0.005351 -0.021096  0.009551 -0.004467  0.005741  0.011742   \n",
       "2023-12-31 -0.023762 -0.023652 -0.021338 -0.023467 -0.014802 -0.012190   \n",
       "\n",
       "                  P7        P8        P9      Pmax  My_portfolio  Raw_return  \\\n",
       "month                                                                          \n",
       "2000-01-31  0.154231  0.133388  0.189671  0.277708     -0.148816    0.123242   \n",
       "2000-02-29  0.080466  0.102473  0.169644  0.125983      0.022476    0.116990   \n",
       "2000-03-31  0.079722  0.081513  0.040770 -0.044828      0.073366    0.049948   \n",
       "2000-04-30  0.021396  0.004873 -0.011356 -0.015714      0.009921    0.020053   \n",
       "2000-05-31  0.025010  0.058083  0.021637  0.036778     -0.016922    0.031710   \n",
       "...              ...       ...       ...       ...           ...         ...   \n",
       "2023-08-31 -0.054358 -0.052533 -0.059833 -0.069041      0.020526   -0.052009   \n",
       "2023-09-30  0.001202 -0.024952 -0.007080 -0.012874     -0.000340   -0.003013   \n",
       "2023-10-31 -0.022298 -0.033380 -0.029932  0.008262     -0.076519   -0.029483   \n",
       "2023-11-30 -0.004673 -0.001100  0.010682  0.005062      0.000289    0.003611   \n",
       "2023-12-31 -0.023572 -0.026295  0.005428 -0.050056      0.026293   -0.018067   \n",
       "\n",
       "            price_portfolio  P1_price  Pmax_price  Market_price  \n",
       "month                                                            \n",
       "2000-01-31         0.851184  1.128892    1.277708      1.123242  \n",
       "2000-02-29         0.870316  1.296487    1.438677      1.254650  \n",
       "2000-03-31         0.934168  1.333486    1.374184      1.317318  \n",
       "2000-04-30         0.943436  1.325762    1.352590      1.343734  \n",
       "2000-05-31         0.927471  1.352086    1.402335      1.386344  \n",
       "...                     ...       ...         ...           ...  \n",
       "2023-08-31         6.946370  4.670596    0.316197      2.282984  \n",
       "2023-09-30         6.944005  4.608875    0.312126      2.276105  \n",
       "2023-10-31         6.412660  4.294287    0.314704      2.208999  \n",
       "2023-11-30         6.414512  4.317264    0.316297      2.216977  \n",
       "2023-12-31         6.583172  4.214677    0.300465      2.176922  \n",
       "\n",
       "[288 rows x 16 columns]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 还原投资组合的价格\n",
    "MYPORT['price_portfolio'] = (1 + MYPORT['My_portfolio']).cumprod()\n",
    "MYPORT['P1_price'] = (1 + MYPORT['P1']).cumprod()\n",
    "MYPORT['Pmax_price'] = (1 + MYPORT['Pmax']).cumprod()\n",
    "MYPORT['Market_price'] = (1 + MYPORT['Raw_return']).cumprod()\n",
    "MYPORT"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 价格图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"711.040625pt\" height=\"281.634375pt\" viewBox=\"0 0 711.040625 281.634375\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2024-11-30T23:56:05.335482</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.8.4, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 281.634375 \n",
       "L 711.040625 281.634375 \n",
       "L 711.040625 0 \n",
       "L 0 0 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 34.240625 244.078125 \n",
       "L 703.840625 244.078125 \n",
       "L 703.840625 22.318125 \n",
       "L 34.240625 22.318125 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <path d=\"M 62.58634 244.078125 \n",
       "L 62.58634 22.318125 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_2\">\n",
       "      <defs>\n",
       "       <path id=\"m0a47a9e89f\" d=\"M 0 0 \n",
       "L 0 3.5 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m0a47a9e89f\" x=\"62.58634\" y=\"244.078125\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_1\">\n",
       "      <!-- 2000 -->\n",
       "      <g transform=\"translate(49.86134 258.676562) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n",
       "L 3431 531 \n",
       "L 3431 0 \n",
       "L 469 0 \n",
       "L 469 531 \n",
       "Q 828 903 1448 1529 \n",
       "Q 2069 2156 2228 2338 \n",
       "Q 2531 2678 2651 2914 \n",
       "Q 2772 3150 2772 3378 \n",
       "Q 2772 3750 2511 3984 \n",
       "Q 2250 4219 1831 4219 \n",
       "Q 1534 4219 1204 4116 \n",
       "Q 875 4013 500 3803 \n",
       "L 500 4441 \n",
       "Q 881 4594 1212 4672 \n",
       "Q 1544 4750 1819 4750 \n",
       "Q 2544 4750 2975 4387 \n",
       "Q 3406 4025 3406 3419 \n",
       "Q 3406 3131 3298 2873 \n",
       "Q 3191 2616 2906 2266 \n",
       "Q 2828 2175 2409 1742 \n",
       "Q 1991 1309 1228 531 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n",
       "Q 1547 4250 1301 3770 \n",
       "Q 1056 3291 1056 2328 \n",
       "Q 1056 1369 1301 889 \n",
       "Q 1547 409 2034 409 \n",
       "Q 2525 409 2770 889 \n",
       "Q 3016 1369 3016 2328 \n",
       "Q 3016 3291 2770 3770 \n",
       "Q 2525 4250 2034 4250 \n",
       "z\n",
       "M 2034 4750 \n",
       "Q 2819 4750 3233 4129 \n",
       "Q 3647 3509 3647 2328 \n",
       "Q 3647 1150 3233 529 \n",
       "Q 2819 -91 2034 -91 \n",
       "Q 1250 -91 836 529 \n",
       "Q 422 1150 422 2328 \n",
       "Q 422 3509 836 4129 \n",
       "Q 1250 4750 2034 4750 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <path d=\"M 164.400941 244.078125 \n",
       "L 164.400941 22.318125 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_4\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m0a47a9e89f\" x=\"164.400941\" y=\"244.078125\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_2\">\n",
       "      <!-- 2004 -->\n",
       "      <g transform=\"translate(151.675941 258.676562) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n",
       "L 825 1625 \n",
       "L 2419 1625 \n",
       "L 2419 4116 \n",
       "z\n",
       "M 2253 4666 \n",
       "L 3047 4666 \n",
       "L 3047 1625 \n",
       "L 3713 1625 \n",
       "L 3713 1100 \n",
       "L 3047 1100 \n",
       "L 3047 0 \n",
       "L 2419 0 \n",
       "L 2419 1100 \n",
       "L 313 1100 \n",
       "L 313 1709 \n",
       "L 2253 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-34\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <path d=\"M 266.215543 244.078125 \n",
       "L 266.215543 22.318125 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_6\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m0a47a9e89f\" x=\"266.215543\" y=\"244.078125\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_3\">\n",
       "      <!-- 2008 -->\n",
       "      <g transform=\"translate(253.490543 258.676562) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \n",
       "Q 1584 2216 1326 1975 \n",
       "Q 1069 1734 1069 1313 \n",
       "Q 1069 891 1326 650 \n",
       "Q 1584 409 2034 409 \n",
       "Q 2484 409 2743 651 \n",
       "Q 3003 894 3003 1313 \n",
       "Q 3003 1734 2745 1975 \n",
       "Q 2488 2216 2034 2216 \n",
       "z\n",
       "M 1403 2484 \n",
       "Q 997 2584 770 2862 \n",
       "Q 544 3141 544 3541 \n",
       "Q 544 4100 942 4425 \n",
       "Q 1341 4750 2034 4750 \n",
       "Q 2731 4750 3128 4425 \n",
       "Q 3525 4100 3525 3541 \n",
       "Q 3525 3141 3298 2862 \n",
       "Q 3072 2584 2669 2484 \n",
       "Q 3125 2378 3379 2068 \n",
       "Q 3634 1759 3634 1313 \n",
       "Q 3634 634 3220 271 \n",
       "Q 2806 -91 2034 -91 \n",
       "Q 1263 -91 848 271 \n",
       "Q 434 634 434 1313 \n",
       "Q 434 1759 690 2068 \n",
       "Q 947 2378 1403 2484 \n",
       "z\n",
       "M 1172 3481 \n",
       "Q 1172 3119 1398 2916 \n",
       "Q 1625 2713 2034 2713 \n",
       "Q 2441 2713 2670 2916 \n",
       "Q 2900 3119 2900 3481 \n",
       "Q 2900 3844 2670 4047 \n",
       "Q 2441 4250 2034 4250 \n",
       "Q 1625 4250 1398 4047 \n",
       "Q 1172 3844 1172 3481 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-38\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <path d=\"M 368.030145 244.078125 \n",
       "L 368.030145 22.318125 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_8\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m0a47a9e89f\" x=\"368.030145\" y=\"244.078125\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_4\">\n",
       "      <!-- 2012 -->\n",
       "      <g transform=\"translate(355.305145 258.676562) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n",
       "L 1825 531 \n",
       "L 1825 4091 \n",
       "L 703 3866 \n",
       "L 703 4441 \n",
       "L 1819 4666 \n",
       "L 2450 4666 \n",
       "L 2450 531 \n",
       "L 3481 531 \n",
       "L 3481 0 \n",
       "L 794 0 \n",
       "L 794 531 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-31\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-32\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <path d=\"M 469.844746 244.078125 \n",
       "L 469.844746 22.318125 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_10\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m0a47a9e89f\" x=\"469.844746\" y=\"244.078125\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_5\">\n",
       "      <!-- 2016 -->\n",
       "      <g transform=\"translate(457.119746 258.676562) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \n",
       "Q 1688 2584 1439 2293 \n",
       "Q 1191 2003 1191 1497 \n",
       "Q 1191 994 1439 701 \n",
       "Q 1688 409 2113 409 \n",
       "Q 2538 409 2786 701 \n",
       "Q 3034 994 3034 1497 \n",
       "Q 3034 2003 2786 2293 \n",
       "Q 2538 2584 2113 2584 \n",
       "z\n",
       "M 3366 4563 \n",
       "L 3366 3988 \n",
       "Q 3128 4100 2886 4159 \n",
       "Q 2644 4219 2406 4219 \n",
       "Q 1781 4219 1451 3797 \n",
       "Q 1122 3375 1075 2522 \n",
       "Q 1259 2794 1537 2939 \n",
       "Q 1816 3084 2150 3084 \n",
       "Q 2853 3084 3261 2657 \n",
       "Q 3669 2231 3669 1497 \n",
       "Q 3669 778 3244 343 \n",
       "Q 2819 -91 2113 -91 \n",
       "Q 1303 -91 875 529 \n",
       "Q 447 1150 447 2328 \n",
       "Q 447 3434 972 4092 \n",
       "Q 1497 4750 2381 4750 \n",
       "Q 2619 4750 2861 4703 \n",
       "Q 3103 4656 3366 4563 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-31\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-36\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <path d=\"M 571.659348 244.078125 \n",
       "L 571.659348 22.318125 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_12\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m0a47a9e89f\" x=\"571.659348\" y=\"244.078125\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_6\">\n",
       "      <!-- 2020 -->\n",
       "      <g transform=\"translate(558.934348 258.676562) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-32\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_7\">\n",
       "     <g id=\"line2d_13\">\n",
       "      <path d=\"M 673.47395 244.078125 \n",
       "L 673.47395 22.318125 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_14\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m0a47a9e89f\" x=\"673.47395\" y=\"244.078125\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_7\">\n",
       "      <!-- 2024 -->\n",
       "      <g transform=\"translate(660.74895 258.676562) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-32\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-34\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_8\">\n",
       "     <!-- Month -->\n",
       "     <g transform=\"translate(353.369531 272.354687) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-4d\" d=\"M 628 4666 \n",
       "L 1569 4666 \n",
       "L 2759 1491 \n",
       "L 3956 4666 \n",
       "L 4897 4666 \n",
       "L 4897 0 \n",
       "L 4281 0 \n",
       "L 4281 4097 \n",
       "L 3078 897 \n",
       "L 2444 897 \n",
       "L 1241 4097 \n",
       "L 1241 0 \n",
       "L 628 0 \n",
       "L 628 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n",
       "Q 1497 3097 1228 2736 \n",
       "Q 959 2375 959 1747 \n",
       "Q 959 1119 1226 758 \n",
       "Q 1494 397 1959 397 \n",
       "Q 2419 397 2687 759 \n",
       "Q 2956 1122 2956 1747 \n",
       "Q 2956 2369 2687 2733 \n",
       "Q 2419 3097 1959 3097 \n",
       "z\n",
       "M 1959 3584 \n",
       "Q 2709 3584 3137 3096 \n",
       "Q 3566 2609 3566 1747 \n",
       "Q 3566 888 3137 398 \n",
       "Q 2709 -91 1959 -91 \n",
       "Q 1206 -91 779 398 \n",
       "Q 353 888 353 1747 \n",
       "Q 353 2609 779 3096 \n",
       "Q 1206 3584 1959 3584 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n",
       "L 3513 0 \n",
       "L 2938 0 \n",
       "L 2938 2094 \n",
       "Q 2938 2591 2744 2837 \n",
       "Q 2550 3084 2163 3084 \n",
       "Q 1697 3084 1428 2787 \n",
       "Q 1159 2491 1159 1978 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2956 \n",
       "Q 1366 3272 1645 3428 \n",
       "Q 1925 3584 2291 3584 \n",
       "Q 2894 3584 3203 3211 \n",
       "Q 3513 2838 3513 2113 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n",
       "L 1172 3500 \n",
       "L 2356 3500 \n",
       "L 2356 3053 \n",
       "L 1172 3053 \n",
       "L 1172 1153 \n",
       "Q 1172 725 1289 603 \n",
       "Q 1406 481 1766 481 \n",
       "L 2356 481 \n",
       "L 2356 0 \n",
       "L 1766 0 \n",
       "Q 1100 0 847 248 \n",
       "Q 594 497 594 1153 \n",
       "L 594 3053 \n",
       "L 172 3053 \n",
       "L 172 3500 \n",
       "L 594 3500 \n",
       "L 594 4494 \n",
       "L 1172 4494 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \n",
       "L 3513 0 \n",
       "L 2938 0 \n",
       "L 2938 2094 \n",
       "Q 2938 2591 2744 2837 \n",
       "Q 2550 3084 2163 3084 \n",
       "Q 1697 3084 1428 2787 \n",
       "Q 1159 2491 1159 1978 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 4863 \n",
       "L 1159 4863 \n",
       "L 1159 2956 \n",
       "Q 1366 3272 1645 3428 \n",
       "Q 1925 3584 2291 3584 \n",
       "Q 2894 3584 3203 3211 \n",
       "Q 3513 2838 3513 2113 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-4d\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6f\" x=\"86.279297\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6e\" x=\"147.460938\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-74\" x=\"210.839844\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-68\" x=\"250.048828\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_15\">\n",
       "      <path d=\"M 34.240625 241.628006 \n",
       "L 703.840625 241.628006 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_16\">\n",
       "      <defs>\n",
       "       <path id=\"m90a5830dea\" d=\"M 0 0 \n",
       "L -3.5 0 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m90a5830dea\" x=\"34.240625\" y=\"241.628006\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_9\">\n",
       "      <!-- 0 -->\n",
       "      <g transform=\"translate(20.878125 245.427224) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_17\">\n",
       "      <path d=\"M 34.240625 215.664327 \n",
       "L 703.840625 215.664327 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_18\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m90a5830dea\" x=\"34.240625\" y=\"215.664327\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_10\">\n",
       "      <!-- 1 -->\n",
       "      <g transform=\"translate(20.878125 219.463545) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-31\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_19\">\n",
       "      <path d=\"M 34.240625 189.700648 \n",
       "L 703.840625 189.700648 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_20\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m90a5830dea\" x=\"34.240625\" y=\"189.700648\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_11\">\n",
       "      <!-- 2 -->\n",
       "      <g transform=\"translate(20.878125 193.499867) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_21\">\n",
       "      <path d=\"M 34.240625 163.736969 \n",
       "L 703.840625 163.736969 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_22\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m90a5830dea\" x=\"34.240625\" y=\"163.736969\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_12\">\n",
       "      <!-- 3 -->\n",
       "      <g transform=\"translate(20.878125 167.536188) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n",
       "Q 3050 2419 3304 2112 \n",
       "Q 3559 1806 3559 1356 \n",
       "Q 3559 666 3084 287 \n",
       "Q 2609 -91 1734 -91 \n",
       "Q 1441 -91 1130 -33 \n",
       "Q 819 25 488 141 \n",
       "L 488 750 \n",
       "Q 750 597 1062 519 \n",
       "Q 1375 441 1716 441 \n",
       "Q 2309 441 2620 675 \n",
       "Q 2931 909 2931 1356 \n",
       "Q 2931 1769 2642 2001 \n",
       "Q 2353 2234 1838 2234 \n",
       "L 1294 2234 \n",
       "L 1294 2753 \n",
       "L 1863 2753 \n",
       "Q 2328 2753 2575 2939 \n",
       "Q 2822 3125 2822 3475 \n",
       "Q 2822 3834 2567 4026 \n",
       "Q 2313 4219 1838 4219 \n",
       "Q 1578 4219 1281 4162 \n",
       "Q 984 4106 628 3988 \n",
       "L 628 4550 \n",
       "Q 988 4650 1302 4700 \n",
       "Q 1616 4750 1894 4750 \n",
       "Q 2613 4750 3031 4423 \n",
       "Q 3450 4097 3450 3541 \n",
       "Q 3450 3153 3228 2886 \n",
       "Q 3006 2619 2597 2516 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-33\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_23\">\n",
       "      <path d=\"M 34.240625 137.77329 \n",
       "L 703.840625 137.77329 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_24\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m90a5830dea\" x=\"34.240625\" y=\"137.77329\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_13\">\n",
       "      <!-- 4 -->\n",
       "      <g transform=\"translate(20.878125 141.572509) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-34\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_25\">\n",
       "      <path d=\"M 34.240625 111.809611 \n",
       "L 703.840625 111.809611 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_26\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m90a5830dea\" x=\"34.240625\" y=\"111.809611\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_14\">\n",
       "      <!-- 5 -->\n",
       "      <g transform=\"translate(20.878125 115.60883) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n",
       "L 3169 4666 \n",
       "L 3169 4134 \n",
       "L 1269 4134 \n",
       "L 1269 2991 \n",
       "Q 1406 3038 1543 3061 \n",
       "Q 1681 3084 1819 3084 \n",
       "Q 2600 3084 3056 2656 \n",
       "Q 3513 2228 3513 1497 \n",
       "Q 3513 744 3044 326 \n",
       "Q 2575 -91 1722 -91 \n",
       "Q 1428 -91 1123 -41 \n",
       "Q 819 9 494 109 \n",
       "L 494 744 \n",
       "Q 775 591 1075 516 \n",
       "Q 1375 441 1709 441 \n",
       "Q 2250 441 2565 725 \n",
       "Q 2881 1009 2881 1497 \n",
       "Q 2881 1984 2565 2268 \n",
       "Q 2250 2553 1709 2553 \n",
       "Q 1456 2553 1204 2497 \n",
       "Q 953 2441 691 2322 \n",
       "L 691 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-35\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_27\">\n",
       "      <path d=\"M 34.240625 85.845932 \n",
       "L 703.840625 85.845932 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_28\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m90a5830dea\" x=\"34.240625\" y=\"85.845932\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_15\">\n",
       "      <!-- 6 -->\n",
       "      <g transform=\"translate(20.878125 89.645151) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-36\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_8\">\n",
       "     <g id=\"line2d_29\">\n",
       "      <path d=\"M 34.240625 59.882253 \n",
       "L 703.840625 59.882253 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_30\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m90a5830dea\" x=\"34.240625\" y=\"59.882253\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_16\">\n",
       "      <!-- 7 -->\n",
       "      <g transform=\"translate(20.878125 63.681472) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-37\" d=\"M 525 4666 \n",
       "L 3525 4666 \n",
       "L 3525 4397 \n",
       "L 1831 0 \n",
       "L 1172 0 \n",
       "L 2766 4134 \n",
       "L 525 4134 \n",
       "L 525 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-37\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_9\">\n",
       "     <g id=\"line2d_31\">\n",
       "      <path d=\"M 34.240625 33.918574 \n",
       "L 703.840625 33.918574 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_32\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m90a5830dea\" x=\"34.240625\" y=\"33.918574\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_17\">\n",
       "      <!-- 8 -->\n",
       "      <g transform=\"translate(20.878125 37.717793) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-38\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_18\">\n",
       "     <!-- Return -->\n",
       "     <g transform=\"translate(14.798438 149.789531) rotate(-90) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-52\" d=\"M 2841 2188 \n",
       "Q 3044 2119 3236 1894 \n",
       "Q 3428 1669 3622 1275 \n",
       "L 4263 0 \n",
       "L 3584 0 \n",
       "L 2988 1197 \n",
       "Q 2756 1666 2539 1819 \n",
       "Q 2322 1972 1947 1972 \n",
       "L 1259 1972 \n",
       "L 1259 0 \n",
       "L 628 0 \n",
       "L 628 4666 \n",
       "L 2053 4666 \n",
       "Q 2853 4666 3247 4331 \n",
       "Q 3641 3997 3641 3322 \n",
       "Q 3641 2881 3436 2590 \n",
       "Q 3231 2300 2841 2188 \n",
       "z\n",
       "M 1259 4147 \n",
       "L 1259 2491 \n",
       "L 2053 2491 \n",
       "Q 2509 2491 2742 2702 \n",
       "Q 2975 2913 2975 3322 \n",
       "Q 2975 3731 2742 3939 \n",
       "Q 2509 4147 2053 4147 \n",
       "L 1259 4147 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n",
       "L 3597 1613 \n",
       "L 953 1613 \n",
       "Q 991 1019 1311 708 \n",
       "Q 1631 397 2203 397 \n",
       "Q 2534 397 2845 478 \n",
       "Q 3156 559 3463 722 \n",
       "L 3463 178 \n",
       "Q 3153 47 2828 -22 \n",
       "Q 2503 -91 2169 -91 \n",
       "Q 1331 -91 842 396 \n",
       "Q 353 884 353 1716 \n",
       "Q 353 2575 817 3079 \n",
       "Q 1281 3584 2069 3584 \n",
       "Q 2775 3584 3186 3129 \n",
       "Q 3597 2675 3597 1894 \n",
       "z\n",
       "M 3022 2063 \n",
       "Q 3016 2534 2758 2815 \n",
       "Q 2500 3097 2075 3097 \n",
       "Q 1594 3097 1305 2825 \n",
       "Q 1016 2553 972 2059 \n",
       "L 3022 2063 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n",
       "L 544 3500 \n",
       "L 1119 3500 \n",
       "L 1119 1403 \n",
       "Q 1119 906 1312 657 \n",
       "Q 1506 409 1894 409 \n",
       "Q 2359 409 2629 706 \n",
       "Q 2900 1003 2900 1516 \n",
       "L 2900 3500 \n",
       "L 3475 3500 \n",
       "L 3475 0 \n",
       "L 2900 0 \n",
       "L 2900 538 \n",
       "Q 2691 219 2414 64 \n",
       "Q 2138 -91 1772 -91 \n",
       "Q 1169 -91 856 284 \n",
       "Q 544 659 544 1381 \n",
       "z\n",
       "M 1991 3584 \n",
       "L 1991 3584 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n",
       "Q 2534 3019 2420 3045 \n",
       "Q 2306 3072 2169 3072 \n",
       "Q 1681 3072 1420 2755 \n",
       "Q 1159 2438 1159 1844 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2956 \n",
       "Q 1341 3275 1631 3429 \n",
       "Q 1922 3584 2338 3584 \n",
       "Q 2397 3584 2469 3576 \n",
       "Q 2541 3569 2628 3553 \n",
       "L 2631 2963 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-52\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-65\" x=\"64.982422\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-74\" x=\"126.505859\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-75\" x=\"165.714844\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-72\" x=\"229.09375\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6e\" x=\"268.457031\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_33\">\n",
       "    <path d=\"M 64.676989 219.528126 \n",
       "L 66.697949 219.031398 \n",
       "L 68.858286 217.373566 \n",
       "L 70.948935 217.13294 \n",
       "L 73.109273 217.54744 \n",
       "L 75.199921 217.543106 \n",
       "L 77.360259 217.859482 \n",
       "L 79.520596 218.050881 \n",
       "L 81.611245 219.172589 \n",
       "L 83.771582 219.656531 \n",
       "L 85.862231 218.920667 \n",
       "L 88.022568 219.177303 \n",
       "L 90.182905 219.094004 \n",
       "L 92.134178 219.680768 \n",
       "L 94.294515 218.689841 \n",
       "L 96.385164 219.242857 \n",
       "L 98.545501 220.192288 \n",
       "L 100.63615 219.515712 \n",
       "L 102.796487 219.655215 \n",
       "L 104.956824 220.139622 \n",
       "L 107.047473 220.100248 \n",
       "L 109.20781 219.863788 \n",
       "L 111.298459 218.488738 \n",
       "L 113.458796 217.817939 \n",
       "L 115.619134 219.238192 \n",
       "L 117.570406 217.567401 \n",
       "L 119.730743 218.270364 \n",
       "L 121.821392 218.552245 \n",
       "L 123.981729 218.701885 \n",
       "L 126.072378 216.721817 \n",
       "L 128.232715 215.429734 \n",
       "L 130.393053 215.560378 \n",
       "L 132.483701 216.435975 \n",
       "L 136.734688 216.56566 \n",
       "L 138.895025 216.801001 \n",
       "L 141.055362 214.123915 \n",
       "L 145.166971 212.900576 \n",
       "L 147.25762 217.073737 \n",
       "L 151.508606 215.250796 \n",
       "L 153.668944 216.142211 \n",
       "L 155.829281 215.097464 \n",
       "L 157.91993 215.171108 \n",
       "L 162.170916 214.823141 \n",
       "L 164.331253 215.475192 \n",
       "L 166.49159 214.156528 \n",
       "L 168.512551 214.693405 \n",
       "L 170.672888 214.901624 \n",
       "L 172.763537 216.908621 \n",
       "L 174.923874 217.074376 \n",
       "L 177.014523 215.847824 \n",
       "L 179.17486 215.483817 \n",
       "L 181.335198 215.753173 \n",
       "L 183.425846 213.851996 \n",
       "L 185.586184 216.339361 \n",
       "L 187.676833 214.632515 \n",
       "L 189.83717 214.25581 \n",
       "L 191.997507 215.275612 \n",
       "L 193.948779 213.996781 \n",
       "L 196.109116 211.998133 \n",
       "L 198.199765 215.834059 \n",
       "L 200.360103 212.894609 \n",
       "L 202.450751 212.370243 \n",
       "L 204.611089 214.319198 \n",
       "L 206.771426 210.14018 \n",
       "L 208.862075 211.054672 \n",
       "L 211.022412 211.773297 \n",
       "L 213.113061 210.765267 \n",
       "L 215.273398 209.541751 \n",
       "L 217.433735 211.51298 \n",
       "L 219.385008 208.970686 \n",
       "L 221.545345 208.271507 \n",
       "L 223.635994 213.685133 \n",
       "L 225.796331 212.419915 \n",
       "L 230.047317 211.209552 \n",
       "L 232.207654 210.781663 \n",
       "L 236.45864 211.272408 \n",
       "L 238.549289 212.841195 \n",
       "L 240.709626 218.181946 \n",
       "L 242.869964 214.724823 \n",
       "L 249.072222 219.580974 \n",
       "L 251.232559 217.021671 \n",
       "L 253.323208 217.264261 \n",
       "L 255.483545 213.543923 \n",
       "L 257.643883 215.673051 \n",
       "L 259.734531 217.508759 \n",
       "L 261.894869 217.906366 \n",
       "L 263.985518 214.785113 \n",
       "L 266.145855 215.82538 \n",
       "L 268.306192 217.526607 \n",
       "L 270.327153 218.36333 \n",
       "L 272.48749 217.839615 \n",
       "L 274.578139 216.162559 \n",
       "L 276.738476 215.142153 \n",
       "L 278.829125 215.243698 \n",
       "L 280.989462 211.147437 \n",
       "L 283.149799 210.361376 \n",
       "L 285.240448 207.494032 \n",
       "L 287.400785 208.20627 \n",
       "L 289.491434 207.240893 \n",
       "L 291.651771 204.063683 \n",
       "L 293.812109 202.252222 \n",
       "L 295.763381 200.399451 \n",
       "L 297.923718 197.396736 \n",
       "L 300.014367 198.113777 \n",
       "L 302.174704 197.021819 \n",
       "L 304.265353 199.665989 \n",
       "L 306.42569 200.023468 \n",
       "L 308.586028 194.652793 \n",
       "L 310.676676 192.824199 \n",
       "L 312.837014 193.290493 \n",
       "L 314.927663 193.307084 \n",
       "L 317.088 192.392977 \n",
       "L 319.248337 190.246869 \n",
       "L 321.199609 192.162687 \n",
       "L 323.359946 191.074384 \n",
       "L 325.450595 191.471085 \n",
       "L 327.610933 196.071935 \n",
       "L 329.701581 195.643114 \n",
       "L 331.861919 190.970068 \n",
       "L 334.022256 194.42017 \n",
       "L 336.112905 197.51914 \n",
       "L 338.273242 197.055381 \n",
       "L 340.363891 188.822749 \n",
       "L 342.524228 185.492803 \n",
       "L 344.684565 184.412374 \n",
       "L 346.635838 178.058218 \n",
       "L 348.796175 176.752065 \n",
       "L 350.886824 178.750654 \n",
       "L 353.047161 179.496134 \n",
       "L 355.13781 177.636438 \n",
       "L 357.298147 175.556006 \n",
       "L 359.458484 178.375017 \n",
       "L 361.549133 177.460242 \n",
       "L 363.70947 174.204767 \n",
       "L 365.800119 174.173388 \n",
       "L 367.960456 167.36662 \n",
       "L 370.120794 166.860431 \n",
       "L 372.141754 161.096774 \n",
       "L 374.302091 157.610193 \n",
       "L 376.39274 155.325114 \n",
       "L 378.553078 155.536074 \n",
       "L 380.643726 155.33229 \n",
       "L 382.804064 157.904258 \n",
       "L 384.964401 152.003631 \n",
       "L 387.05505 143.187704 \n",
       "L 389.215387 138.889242 \n",
       "L 391.306036 142.140644 \n",
       "L 393.466373 136.054174 \n",
       "L 395.62671 138.462751 \n",
       "L 397.577983 142.986714 \n",
       "L 399.73832 149.985592 \n",
       "L 401.828969 148.137176 \n",
       "L 403.989306 146.669088 \n",
       "L 406.079955 149.098374 \n",
       "L 408.240292 145.116593 \n",
       "L 410.400629 141.473407 \n",
       "L 412.491278 143.678524 \n",
       "L 414.651615 134.75438 \n",
       "L 416.742264 131.652795 \n",
       "L 418.902601 131.596859 \n",
       "L 421.062939 132.098741 \n",
       "L 423.014211 130.197809 \n",
       "L 425.174548 123.822392 \n",
       "L 427.265197 124.361103 \n",
       "L 429.425534 122.327124 \n",
       "L 431.516183 124.259487 \n",
       "L 435.836858 107.594878 \n",
       "L 437.927506 118.511256 \n",
       "L 440.087844 119.645815 \n",
       "L 442.178493 132.266603 \n",
       "L 444.33883 170.438267 \n",
       "L 446.499167 156.104387 \n",
       "L 448.450439 162.265466 \n",
       "L 450.610776 170.634146 \n",
       "L 452.701425 176.859008 \n",
       "L 454.861763 166.51848 \n",
       "L 456.952411 146.48719 \n",
       "L 459.112749 139.82917 \n",
       "L 461.273086 135.529778 \n",
       "L 463.363735 124.04251 \n",
       "L 465.524072 120.108012 \n",
       "L 467.614721 126.308467 \n",
       "L 469.775058 121.037199 \n",
       "L 471.935395 116.341704 \n",
       "L 473.956356 117.618202 \n",
       "L 476.116693 100.401011 \n",
       "L 478.207342 95.543036 \n",
       "L 480.367679 92.975042 \n",
       "L 482.458328 93.032484 \n",
       "L 484.618665 83.927454 \n",
       "L 486.779002 71.29319 \n",
       "L 488.869651 73.128256 \n",
       "L 491.029989 65.298168 \n",
       "L 493.120637 76.790892 \n",
       "L 495.280975 72.577764 \n",
       "L 497.441312 69.59459 \n",
       "L 499.392584 58.865203 \n",
       "L 501.552921 60.857454 \n",
       "L 503.64357 74.684604 \n",
       "L 505.803908 91.779699 \n",
       "L 507.894556 86.609768 \n",
       "L 510.054894 95.046064 \n",
       "L 512.215231 86.569637 \n",
       "L 514.30588 85.987467 \n",
       "L 516.466217 89.605921 \n",
       "L 518.556866 91.47012 \n",
       "L 520.717203 91.459704 \n",
       "L 522.87754 94.132972 \n",
       "L 524.828813 83.017444 \n",
       "L 526.98915 84.418737 \n",
       "L 529.079799 84.212142 \n",
       "L 531.240136 91.702842 \n",
       "L 533.330785 94.160249 \n",
       "L 535.491122 93.547836 \n",
       "L 537.651459 102.058251 \n",
       "L 539.742108 106.900229 \n",
       "L 541.902445 107.046349 \n",
       "L 543.993094 99.723074 \n",
       "L 546.153431 97.300864 \n",
       "L 548.313769 96.158938 \n",
       "L 550.265041 67.730374 \n",
       "L 552.425378 77.784979 \n",
       "L 554.516027 72.941075 \n",
       "L 556.676364 72.148197 \n",
       "L 558.767013 62.293401 \n",
       "L 560.92735 59.896655 \n",
       "L 563.087687 68.137143 \n",
       "L 565.178336 64.689843 \n",
       "L 567.338674 63.515077 \n",
       "L 569.429323 58.532739 \n",
       "L 571.58966 67.186468 \n",
       "L 573.749997 71.149567 \n",
       "L 575.770958 85.365837 \n",
       "L 577.931295 76.281656 \n",
       "L 580.021944 59.258782 \n",
       "L 582.182281 67.319561 \n",
       "L 584.27293 68.117576 \n",
       "L 586.433267 77.435394 \n",
       "L 588.593604 74.745981 \n",
       "L 590.684253 72.386446 \n",
       "L 592.84459 81.090935 \n",
       "L 594.935239 85.494657 \n",
       "L 597.095576 87.792064 \n",
       "L 599.255914 105.624592 \n",
       "L 601.207186 97.475418 \n",
       "L 603.367523 95.36062 \n",
       "L 605.458172 90.321973 \n",
       "L 607.618509 94.946606 \n",
       "L 609.709158 102.290804 \n",
       "L 611.869495 122.284132 \n",
       "L 614.029832 139.852139 \n",
       "L 616.120481 125.973522 \n",
       "L 618.280819 117.789958 \n",
       "L 620.371467 118.125786 \n",
       "L 622.531805 107.678918 \n",
       "L 624.692142 108.207299 \n",
       "L 626.643414 103.365245 \n",
       "L 628.803751 104.56695 \n",
       "L 630.8944 102.987156 \n",
       "L 633.054738 90.153522 \n",
       "L 635.145386 97.10567 \n",
       "L 637.305724 94.09167 \n",
       "L 639.466061 80.830446 \n",
       "L 641.55671 89.565805 \n",
       "L 643.717047 76.567812 \n",
       "L 645.807696 47.564355 \n",
       "L 647.968033 51.627332 \n",
       "L 650.12837 42.379173 \n",
       "L 652.079643 32.398125 \n",
       "L 654.23998 50.43125 \n",
       "L 656.330629 73.959255 \n",
       "L 658.490966 71.199709 \n",
       "L 660.581615 77.86794 \n",
       "L 662.741952 64.902162 \n",
       "L 664.902289 61.274694 \n",
       "L 666.992938 61.336086 \n",
       "L 669.153275 75.131767 \n",
       "L 671.243924 75.083666 \n",
       "L 673.404261 70.704644 \n",
       "L 673.404261 70.704644 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_34\">\n",
       "    <path d=\"M 64.676989 208.454015 \n",
       "L 66.697949 204.274646 \n",
       "L 68.858286 205.949137 \n",
       "L 70.948935 206.50979 \n",
       "L 73.109273 205.218229 \n",
       "L 75.199921 205.324186 \n",
       "L 77.360259 203.758314 \n",
       "L 79.520596 203.278661 \n",
       "L 81.611245 203.848236 \n",
       "L 83.771582 202.433183 \n",
       "L 85.862231 201.361551 \n",
       "L 88.022568 201.511102 \n",
       "L 90.182905 202.674119 \n",
       "L 92.134178 204.40958 \n",
       "L 94.294515 202.192929 \n",
       "L 96.385164 201.233093 \n",
       "L 98.545501 198.761804 \n",
       "L 100.63615 200.300371 \n",
       "L 102.796487 205.710419 \n",
       "L 104.956824 206.421849 \n",
       "L 107.047473 208.252449 \n",
       "L 109.20781 209.142703 \n",
       "L 111.298459 209.382498 \n",
       "L 115.619134 214.738205 \n",
       "L 117.570406 214.492768 \n",
       "L 119.730743 212.36577 \n",
       "L 121.821392 211.51306 \n",
       "L 123.981729 214.147009 \n",
       "L 126.072378 211.973665 \n",
       "L 128.232715 213.922874 \n",
       "L 130.393053 213.704481 \n",
       "L 134.644039 215.770929 \n",
       "L 136.734688 217.093311 \n",
       "L 138.895025 217.882147 \n",
       "L 141.055362 217.268907 \n",
       "L 143.006634 217.549395 \n",
       "L 145.166971 218.135453 \n",
       "L 147.25762 216.674476 \n",
       "L 149.417958 215.754212 \n",
       "L 151.508606 218.157199 \n",
       "L 153.668944 217.919635 \n",
       "L 157.91993 220.196381 \n",
       "L 160.080267 221.765711 \n",
       "L 162.170916 220.872681 \n",
       "L 164.331253 220.546643 \n",
       "L 166.49159 219.812325 \n",
       "L 168.512551 218.490596 \n",
       "L 170.672888 218.022698 \n",
       "L 172.763537 220.0968 \n",
       "L 174.923874 220.757008 \n",
       "L 177.014523 224.2019 \n",
       "L 179.17486 224.233483 \n",
       "L 181.335198 225.317827 \n",
       "L 183.425846 225.186768 \n",
       "L 185.586184 225.297494 \n",
       "L 187.676833 225.55001 \n",
       "L 189.83717 226.863298 \n",
       "L 191.997507 227.42469 \n",
       "L 193.948779 226.328137 \n",
       "L 196.109116 228.216256 \n",
       "L 198.199765 227.752514 \n",
       "L 200.360103 229.521477 \n",
       "L 202.450751 229.477923 \n",
       "L 204.611089 229.302571 \n",
       "L 206.771426 228.939809 \n",
       "L 208.862075 228.7616 \n",
       "L 213.113061 229.594011 \n",
       "L 215.273398 229.125843 \n",
       "L 217.433735 227.784876 \n",
       "L 219.385008 227.992292 \n",
       "L 221.545345 227.479398 \n",
       "L 223.635994 224.816239 \n",
       "L 225.796331 221.29298 \n",
       "L 227.88698 221.097379 \n",
       "L 230.047317 222.575093 \n",
       "L 232.207654 221.743258 \n",
       "L 234.298303 220.329151 \n",
       "L 236.45864 220.060633 \n",
       "L 238.549289 216.344237 \n",
       "L 240.709626 210.74482 \n",
       "L 244.821236 204.225947 \n",
       "L 246.981573 198.650956 \n",
       "L 249.072222 184.680255 \n",
       "L 251.232559 181.484747 \n",
       "L 253.323208 188.482807 \n",
       "L 255.483545 179.850963 \n",
       "L 257.643883 169.641945 \n",
       "L 259.734531 165.877589 \n",
       "L 261.894869 169.321433 \n",
       "L 263.985518 182.841469 \n",
       "L 266.145855 172.702323 \n",
       "L 268.306192 179.241132 \n",
       "L 270.327153 176.325811 \n",
       "L 272.48749 188.387483 \n",
       "L 274.578139 189.547486 \n",
       "L 276.738476 195.255701 \n",
       "L 278.829125 205.126777 \n",
       "L 280.989462 206.832754 \n",
       "L 283.149799 214.131042 \n",
       "L 285.240448 217.734396 \n",
       "L 287.400785 224.075247 \n",
       "L 289.491434 221.665546 \n",
       "L 291.651771 222.41491 \n",
       "L 293.812109 220.886961 \n",
       "L 295.763381 220.488395 \n",
       "L 297.923718 216.394871 \n",
       "L 302.174704 213.466959 \n",
       "L 304.265353 210.309335 \n",
       "L 306.42569 206.188318 \n",
       "L 308.586028 215.888299 \n",
       "L 310.676676 215.152768 \n",
       "L 312.837014 212.454718 \n",
       "L 314.927663 210.181822 \n",
       "L 317.088 210.300007 \n",
       "L 319.248337 214.757454 \n",
       "L 321.199609 213.081778 \n",
       "L 323.359946 213.050702 \n",
       "L 325.450595 214.554045 \n",
       "L 327.610933 215.031096 \n",
       "L 329.701581 218.03085 \n",
       "L 331.861919 216.598986 \n",
       "L 334.022256 214.719886 \n",
       "L 336.112905 213.558525 \n",
       "L 338.273242 210.590148 \n",
       "L 340.363891 213.791895 \n",
       "L 342.524228 215.087868 \n",
       "L 344.684565 216.584878 \n",
       "L 346.635838 216.420446 \n",
       "L 348.796175 216.611319 \n",
       "L 350.886824 217.133424 \n",
       "L 353.047161 218.925445 \n",
       "L 355.13781 218.181652 \n",
       "L 359.458484 219.635788 \n",
       "L 361.549133 222.624585 \n",
       "L 363.70947 222.343969 \n",
       "L 365.800119 223.823088 \n",
       "L 367.960456 227.186587 \n",
       "L 370.120794 226.619056 \n",
       "L 372.141754 225.448672 \n",
       "L 374.302091 227.247592 \n",
       "L 376.39274 226.518033 \n",
       "L 378.553078 226.434799 \n",
       "L 382.804064 227.96093 \n",
       "L 384.964401 228.629023 \n",
       "L 387.05505 228.991598 \n",
       "L 389.215387 229.549473 \n",
       "L 391.306036 230.451506 \n",
       "L 393.466373 228.844294 \n",
       "L 395.62671 228.104553 \n",
       "L 397.577983 227.658658 \n",
       "L 399.73832 227.560777 \n",
       "L 401.828969 227.964149 \n",
       "L 403.989306 226.23722 \n",
       "L 406.079955 228.219823 \n",
       "L 408.240292 228.254438 \n",
       "L 410.400629 227.830962 \n",
       "L 412.491278 226.691847 \n",
       "L 414.651615 228.475214 \n",
       "L 416.742264 227.899671 \n",
       "L 418.902601 228.734223 \n",
       "L 421.062939 228.591746 \n",
       "L 423.014211 228.847179 \n",
       "L 425.174548 230.004765 \n",
       "L 427.265197 230.151852 \n",
       "L 429.425534 230.044765 \n",
       "L 431.516183 229.593904 \n",
       "L 433.67652 229.320067 \n",
       "L 435.836858 229.418049 \n",
       "L 437.927506 228.039193 \n",
       "L 440.087844 227.802787 \n",
       "L 442.178493 225.899457 \n",
       "L 444.33883 221.050651 \n",
       "L 446.499167 222.059253 \n",
       "L 448.450439 220.170172 \n",
       "L 450.610776 215.704395 \n",
       "L 452.701425 209.605652 \n",
       "L 454.861763 207.788312 \n",
       "L 456.952411 217.269513 \n",
       "L 459.112749 222.58919 \n",
       "L 461.273086 226.15145 \n",
       "L 463.363735 227.902402 \n",
       "L 465.524072 225.423855 \n",
       "L 467.614721 224.507409 \n",
       "L 469.775058 224.842435 \n",
       "L 471.935395 230.602084 \n",
       "L 473.956356 230.746452 \n",
       "L 476.116693 229.733474 \n",
       "L 478.207342 230.255199 \n",
       "L 480.367679 230.57418 \n",
       "L 482.458328 230.076812 \n",
       "L 484.618665 230.814899 \n",
       "L 486.779002 230.742775 \n",
       "L 488.869651 230.91369 \n",
       "L 491.029989 230.753237 \n",
       "L 493.120637 229.802049 \n",
       "L 495.280975 230.788714 \n",
       "L 497.441312 231.252367 \n",
       "L 499.392584 231.258557 \n",
       "L 501.552921 231.421565 \n",
       "L 503.64357 231.411829 \n",
       "L 505.803908 231.539123 \n",
       "L 512.215231 230.526001 \n",
       "L 514.30588 230.576952 \n",
       "L 516.466217 230.411097 \n",
       "L 518.556866 230.696622 \n",
       "L 520.717203 230.836077 \n",
       "L 522.87754 230.527658 \n",
       "L 524.828813 231.404751 \n",
       "L 526.98915 231.418291 \n",
       "L 529.079799 231.756742 \n",
       "L 531.240136 231.589905 \n",
       "L 533.330785 232.389227 \n",
       "L 535.491122 232.33433 \n",
       "L 537.651459 232.78522 \n",
       "L 539.742108 232.361496 \n",
       "L 541.902445 233.514486 \n",
       "L 543.993094 233.51446 \n",
       "L 546.153431 233.964965 \n",
       "L 548.313769 233.998125 \n",
       "L 550.265041 232.978908 \n",
       "L 552.425378 232.282241 \n",
       "L 554.516027 232.583822 \n",
       "L 556.676364 233.25337 \n",
       "L 558.767013 233.451311 \n",
       "L 560.92735 233.507061 \n",
       "L 563.087687 233.313404 \n",
       "L 567.338674 233.349757 \n",
       "L 569.429323 233.565156 \n",
       "L 571.58966 232.58414 \n",
       "L 573.749997 232.382792 \n",
       "L 575.770958 231.709928 \n",
       "L 577.931295 232.841284 \n",
       "L 580.021944 232.690887 \n",
       "L 582.182281 232.296533 \n",
       "L 584.27293 231.414052 \n",
       "L 586.433267 229.746768 \n",
       "L 588.593604 229.809424 \n",
       "L 590.684253 230.62074 \n",
       "L 592.84459 230.340184 \n",
       "L 594.935239 229.863982 \n",
       "L 597.095576 229.235152 \n",
       "L 599.255914 228.857144 \n",
       "L 601.207186 229.305862 \n",
       "L 603.367523 229.964394 \n",
       "L 605.458172 229.979449 \n",
       "L 607.618509 228.902284 \n",
       "L 609.709158 228.366037 \n",
       "L 611.869495 227.559444 \n",
       "L 614.029832 226.131204 \n",
       "L 616.120481 227.603606 \n",
       "L 618.280819 228.139489 \n",
       "L 620.371467 227.980282 \n",
       "L 622.531805 228.77562 \n",
       "L 624.692142 230.264386 \n",
       "L 626.643414 229.877594 \n",
       "L 628.803751 230.776866 \n",
       "L 630.8944 231.870838 \n",
       "L 633.054738 231.768955 \n",
       "L 635.145386 230.548038 \n",
       "L 637.305724 230.901394 \n",
       "L 639.466061 232.06157 \n",
       "L 641.55671 232.447472 \n",
       "L 643.717047 233.165795 \n",
       "L 647.968033 233.411783 \n",
       "L 650.12837 233.070763 \n",
       "L 652.079643 233.323282 \n",
       "L 654.23998 232.994718 \n",
       "L 656.330629 232.415274 \n",
       "L 658.490966 232.741611 \n",
       "L 660.581615 232.30635 \n",
       "L 664.902289 233.41838 \n",
       "L 666.992938 233.524075 \n",
       "L 671.243924 233.415764 \n",
       "L 673.404261 233.826834 \n",
       "L 673.404261 233.826834 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_35\">\n",
       "    <path d=\"M 64.676989 212.317815 \n",
       "L 66.697949 207.966429 \n",
       "L 68.858286 207.005795 \n",
       "L 70.948935 207.206359 \n",
       "L 73.109273 206.522891 \n",
       "L 75.199921 206.618734 \n",
       "L 77.360259 205.568576 \n",
       "L 79.520596 205.402225 \n",
       "L 81.611245 207.66374 \n",
       "L 83.771582 207.123571 \n",
       "L 85.862231 205.024565 \n",
       "L 88.022568 205.5742 \n",
       "L 90.182905 206.485654 \n",
       "L 92.134178 208.966378 \n",
       "L 94.294515 205.546434 \n",
       "L 96.385164 205.538111 \n",
       "L 98.545501 204.860893 \n",
       "L 100.63615 205.020067 \n",
       "L 102.796487 210.043232 \n",
       "L 104.956824 211.36515 \n",
       "L 107.047473 212.883264 \n",
       "L 109.20781 213.334266 \n",
       "L 111.298459 211.755538 \n",
       "L 113.458796 213.393811 \n",
       "L 115.619134 217.613015 \n",
       "L 117.570406 215.601752 \n",
       "L 119.730743 214.322074 \n",
       "L 121.821392 213.8559 \n",
       "L 123.981729 216.465031 \n",
       "L 126.072378 212.30175 \n",
       "L 128.232715 212.708006 \n",
       "L 130.393053 212.624253 \n",
       "L 132.483701 214.714477 \n",
       "L 134.644039 215.799318 \n",
       "L 136.734688 217.166561 \n",
       "L 138.895025 218.18274 \n",
       "L 141.055362 215.049169 \n",
       "L 143.006634 214.763603 \n",
       "L 145.166971 214.833547 \n",
       "L 147.25762 217.059591 \n",
       "L 149.417958 215.212461 \n",
       "L 151.508606 216.751479 \n",
       "L 153.668944 217.340386 \n",
       "L 155.829281 217.512762 \n",
       "L 157.91993 218.794211 \n",
       "L 160.080267 220.279187 \n",
       "L 162.170916 219.214262 \n",
       "L 164.331253 219.407406 \n",
       "L 166.49159 217.513009 \n",
       "L 168.512551 216.523255 \n",
       "L 170.672888 216.209645 \n",
       "L 172.763537 220.351824 \n",
       "L 174.923874 221.14688 \n",
       "L 177.014523 223.504306 \n",
       "L 179.17486 223.281254 \n",
       "L 181.335198 224.61398 \n",
       "L 183.425846 223.227143 \n",
       "L 185.586184 224.99888 \n",
       "L 187.676833 224.133638 \n",
       "L 191.997507 226.546266 \n",
       "L 193.948779 224.650007 \n",
       "L 196.109116 225.517151 \n",
       "L 198.199765 227.045815 \n",
       "L 200.360103 227.243104 \n",
       "L 202.450751 226.928838 \n",
       "L 204.611089 227.695857 \n",
       "L 206.771426 225.153794 \n",
       "L 208.862075 225.400866 \n",
       "L 211.022412 226.308602 \n",
       "L 213.113061 226.302152 \n",
       "L 215.273398 225.098343 \n",
       "L 217.433735 224.340897 \n",
       "L 219.385008 223.140547 \n",
       "L 221.545345 222.049351 \n",
       "L 223.635994 221.541644 \n",
       "L 225.796331 216.422639 \n",
       "L 227.88698 215.623869 \n",
       "L 230.047317 217.002781 \n",
       "L 232.207654 215.581266 \n",
       "L 234.298303 213.911889 \n",
       "L 236.45864 213.810488 \n",
       "L 238.549289 210.454712 \n",
       "L 240.709626 209.334493 \n",
       "L 242.869964 201.081184 \n",
       "L 244.821236 199.560331 \n",
       "L 246.981573 196.002577 \n",
       "L 249.072222 184.485071 \n",
       "L 251.232559 174.645242 \n",
       "L 253.323208 183.099495 \n",
       "L 255.483545 164.656004 \n",
       "L 257.643883 157.771381 \n",
       "L 259.734531 159.317179 \n",
       "L 261.894869 164.416178 \n",
       "L 263.985518 168.69401 \n",
       "L 266.145855 158.941271 \n",
       "L 268.306192 172.237285 \n",
       "L 270.327153 171.403699 \n",
       "L 272.48749 182.793682 \n",
       "L 274.578139 179.927808 \n",
       "L 276.738476 184.218033 \n",
       "L 278.829125 196.658756 \n",
       "L 280.989462 191.778866 \n",
       "L 283.149799 200.949143 \n",
       "L 285.240448 202.549423 \n",
       "L 287.400785 213.735451 \n",
       "L 289.491434 209.100601 \n",
       "L 291.651771 207.316254 \n",
       "L 293.812109 202.93295 \n",
       "L 295.763381 200.368635 \n",
       "L 297.923718 189.374114 \n",
       "L 300.014367 187.193149 \n",
       "L 302.174704 182.838468 \n",
       "L 304.265353 179.731482 \n",
       "L 306.42569 172.114232 \n",
       "L 308.586028 182.16698 \n",
       "L 310.676676 178.153212 \n",
       "L 314.927663 166.912808 \n",
       "L 317.088 165.780195 \n",
       "L 319.248337 173.265928 \n",
       "L 321.199609 171.551773 \n",
       "L 323.359946 169.933716 \n",
       "L 325.450595 174.267873 \n",
       "L 327.610933 181.633663 \n",
       "L 329.701581 187.835446 \n",
       "L 331.861919 179.104867 \n",
       "L 334.022256 178.669019 \n",
       "L 336.112905 180.084652 \n",
       "L 338.273242 172.929312 \n",
       "L 340.363891 167.327254 \n",
       "L 342.524228 166.101022 \n",
       "L 344.684565 168.907498 \n",
       "L 346.635838 160.353951 \n",
       "L 348.796175 159.299443 \n",
       "L 350.886824 163.553902 \n",
       "L 353.047161 170.191449 \n",
       "L 355.13781 165.712809 \n",
       "L 357.298147 165.410663 \n",
       "L 359.458484 171.289916 \n",
       "L 361.549133 179.831796 \n",
       "L 363.70947 175.78412 \n",
       "L 367.960456 186.156318 \n",
       "L 370.120794 183.598234 \n",
       "L 372.141754 174.599745 \n",
       "L 374.302091 179.150395 \n",
       "L 376.39274 174.281492 \n",
       "L 378.553078 174.075133 \n",
       "L 380.643726 177.483008 \n",
       "L 382.804064 182.620628 \n",
       "L 384.964401 181.346427 \n",
       "L 387.05505 177.09822 \n",
       "L 389.215387 177.129356 \n",
       "L 391.306036 183.987366 \n",
       "L 393.466373 172.172122 \n",
       "L 395.62671 169.737575 \n",
       "L 397.577983 170.519717 \n",
       "L 399.73832 175.066804 \n",
       "L 401.828969 175.63289 \n",
       "L 403.989306 166.255663 \n",
       "L 406.079955 177.893153 \n",
       "L 408.240292 175.315025 \n",
       "L 412.491278 166.418366 \n",
       "L 414.651615 168.546016 \n",
       "L 416.742264 163.227162 \n",
       "L 418.902601 167.953313 \n",
       "L 421.062939 167.47525 \n",
       "L 423.014211 167.64125 \n",
       "L 425.174548 170.109273 \n",
       "L 427.265197 171.341354 \n",
       "L 429.425534 169.466381 \n",
       "L 431.516183 167.826423 \n",
       "L 433.67652 160.933487 \n",
       "L 435.836858 156.198816 \n",
       "L 437.927506 153.509204 \n",
       "L 440.087844 152.788234 \n",
       "L 442.178493 149.74932 \n",
       "L 444.33883 153.494382 \n",
       "L 446.499167 140.068775 \n",
       "L 448.450439 137.580967 \n",
       "L 450.610776 126.898462 \n",
       "L 452.701425 109.967073 \n",
       "L 454.861763 81.475033 \n",
       "L 456.952411 83.634771 \n",
       "L 459.112749 107.082604 \n",
       "L 461.273086 126.574324 \n",
       "L 463.363735 127.134129 \n",
       "L 465.524072 102.62797 \n",
       "L 467.614721 101.859007 \n",
       "L 469.775058 98.205236 \n",
       "L 471.935395 141.83351 \n",
       "L 473.956356 144.156949 \n",
       "L 476.116693 121.550613 \n",
       "L 480.367679 123.932242 \n",
       "L 482.458328 118.681989 \n",
       "L 484.618665 119.004486 \n",
       "L 486.779002 108.362534 \n",
       "L 488.869651 111.890718 \n",
       "L 491.029989 103.91901 \n",
       "L 493.120637 100.849468 \n",
       "L 495.280975 108.996723 \n",
       "L 497.441312 112.329556 \n",
       "L 499.392584 104.342606 \n",
       "L 501.552921 107.997242 \n",
       "L 503.64357 118.091194 \n",
       "L 505.803908 132.280705 \n",
       "L 507.894556 124.657133 \n",
       "L 510.054894 126.453674 \n",
       "L 512.215231 117.141925 \n",
       "L 514.30588 117.245847 \n",
       "L 516.466217 118.270843 \n",
       "L 518.556866 122.923579 \n",
       "L 520.717203 124.429689 \n",
       "L 522.87754 123.166667 \n",
       "L 524.828813 123.599385 \n",
       "L 526.98915 124.798466 \n",
       "L 529.079799 128.517822 \n",
       "L 531.240136 131.988513 \n",
       "L 533.330785 142.516066 \n",
       "L 535.491122 141.515543 \n",
       "L 537.651459 152.12621 \n",
       "L 539.742108 150.942515 \n",
       "L 541.902445 162.32446 \n",
       "L 543.993094 158.008894 \n",
       "L 546.153431 161.22453 \n",
       "L 548.313769 160.936302 \n",
       "L 550.265041 134.387989 \n",
       "L 552.425378 131.950546 \n",
       "L 554.516027 132.247224 \n",
       "L 556.676364 139.830647 \n",
       "L 558.767013 136.31746 \n",
       "L 560.92735 135.628044 \n",
       "L 563.087687 137.906812 \n",
       "L 565.178336 136.381286 \n",
       "L 567.338674 135.598924 \n",
       "L 569.429323 135.391849 \n",
       "L 571.58966 127.487072 \n",
       "L 573.749997 127.539033 \n",
       "L 575.770958 128.749594 \n",
       "L 577.931295 135.063553 \n",
       "L 580.021944 122.268432 \n",
       "L 582.182281 122.277378 \n",
       "L 584.27293 111.536751 \n",
       "L 586.433267 97.287319 \n",
       "L 588.593604 95.684261 \n",
       "L 590.684253 103.639438 \n",
       "L 592.84459 107.219425 \n",
       "L 594.935239 105.236083 \n",
       "L 597.095576 99.952367 \n",
       "L 599.255914 112.053872 \n",
       "L 601.207186 108.842662 \n",
       "L 603.367523 113.991071 \n",
       "L 605.458172 109.758958 \n",
       "L 607.618509 101.595321 \n",
       "L 609.709158 102.705804 \n",
       "L 611.869495 114.190344 \n",
       "L 614.029832 120.012326 \n",
       "L 616.120481 114.983369 \n",
       "L 618.280819 110.861338 \n",
       "L 620.371467 109.672497 \n",
       "L 622.531805 106.200455 \n",
       "L 624.692142 122.422014 \n",
       "L 626.643414 114.038341 \n",
       "L 630.8944 135.333454 \n",
       "L 633.054738 124.384121 \n",
       "L 635.145386 115.246056 \n",
       "L 637.305724 116.640877 \n",
       "L 639.466061 118.924915 \n",
       "L 641.55671 130.54052 \n",
       "L 643.717047 129.736918 \n",
       "L 645.807696 111.793336 \n",
       "L 647.968033 116.320835 \n",
       "L 650.12837 105.020626 \n",
       "L 652.079643 102.208704 \n",
       "L 654.23998 108.709061 \n",
       "L 656.330629 116.144438 \n",
       "L 658.490966 118.524118 \n",
       "L 660.581615 117.311012 \n",
       "L 662.741952 114.178904 \n",
       "L 664.902289 120.362146 \n",
       "L 666.992938 121.964653 \n",
       "L 669.153275 130.132511 \n",
       "L 671.243924 129.535938 \n",
       "L 673.404261 132.199498 \n",
       "L 673.404261 132.199498 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #2ca02c; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_36\">\n",
       "    <path d=\"M 64.676989 212.464512 \n",
       "L 66.697949 209.052668 \n",
       "L 68.858286 207.425592 \n",
       "L 70.948935 206.739728 \n",
       "L 73.109273 205.633415 \n",
       "L 75.199921 204.995808 \n",
       "L 77.360259 203.182731 \n",
       "L 79.520596 203.227189 \n",
       "L 81.611245 205.33684 \n",
       "L 83.771582 204.36542 \n",
       "L 85.862231 202.288448 \n",
       "L 88.022568 202.23392 \n",
       "L 90.182905 202.383443 \n",
       "L 92.134178 204.405508 \n",
       "L 94.294515 201.487259 \n",
       "L 96.385164 201.365665 \n",
       "L 98.545501 199.559239 \n",
       "L 100.63615 199.487612 \n",
       "L 102.796487 205.14381 \n",
       "L 104.956824 206.781146 \n",
       "L 109.20781 209.535433 \n",
       "L 111.298459 208.417911 \n",
       "L 113.458796 210.356191 \n",
       "L 115.619134 213.287929 \n",
       "L 117.570406 212.660202 \n",
       "L 119.730743 211.15548 \n",
       "L 121.821392 209.942392 \n",
       "L 123.981729 212.830623 \n",
       "L 126.072378 208.707266 \n",
       "L 128.232715 210.249416 \n",
       "L 130.393053 209.963861 \n",
       "L 132.483701 211.578778 \n",
       "L 138.895025 215.833988 \n",
       "L 141.055362 213.132897 \n",
       "L 143.006634 212.902819 \n",
       "L 145.166971 212.928468 \n",
       "L 147.25762 212.722139 \n",
       "L 149.417958 211.680612 \n",
       "L 151.508606 213.395084 \n",
       "L 153.668944 213.571395 \n",
       "L 157.91993 215.653307 \n",
       "L 160.080267 216.011629 \n",
       "L 162.170916 215.082197 \n",
       "L 166.49159 211.405697 \n",
       "L 168.512551 209.803319 \n",
       "L 170.672888 208.538935 \n",
       "L 172.763537 211.313361 \n",
       "L 174.923874 212.067243 \n",
       "L 177.014523 215.045339 \n",
       "L 179.17486 215.291566 \n",
       "L 181.335198 216.130183 \n",
       "L 183.425846 215.092076 \n",
       "L 185.586184 216.539042 \n",
       "L 187.676833 216.154691 \n",
       "L 191.997507 218.984595 \n",
       "L 193.948779 216.815287 \n",
       "L 196.109116 219.185605 \n",
       "L 198.199765 219.605293 \n",
       "L 200.360103 221.474987 \n",
       "L 202.450751 221.091206 \n",
       "L 204.611089 221.051498 \n",
       "L 206.771426 219.535947 \n",
       "L 208.862075 219.67255 \n",
       "L 211.022412 220.865498 \n",
       "L 213.113061 220.743144 \n",
       "L 215.273398 219.569005 \n",
       "L 217.433735 217.72629 \n",
       "L 219.385008 216.94771 \n",
       "L 221.545345 216.96158 \n",
       "L 223.635994 214.265239 \n",
       "L 225.796331 210.444916 \n",
       "L 227.88698 209.857657 \n",
       "L 230.047317 210.987718 \n",
       "L 232.207654 210.115473 \n",
       "L 234.298303 208.333745 \n",
       "L 236.45864 206.707999 \n",
       "L 238.549289 201.743556 \n",
       "L 240.709626 190.796701 \n",
       "L 244.821236 186.890503 \n",
       "L 246.981573 181.13551 \n",
       "L 249.072222 168.647645 \n",
       "L 251.232559 163.548689 \n",
       "L 253.323208 169.038455 \n",
       "L 255.483545 156.682823 \n",
       "L 257.643883 142.475547 \n",
       "L 259.734531 136.139754 \n",
       "L 261.894869 128.493219 \n",
       "L 263.985518 149.068966 \n",
       "L 266.145855 141.663529 \n",
       "L 268.306192 158.347897 \n",
       "L 270.327153 159.010013 \n",
       "L 272.48749 175.649924 \n",
       "L 274.578139 171.46254 \n",
       "L 276.738476 176.397725 \n",
       "L 278.829125 189.644791 \n",
       "L 280.989462 188.89205 \n",
       "L 283.149799 196.080328 \n",
       "L 285.240448 198.048437 \n",
       "L 287.400785 208.782692 \n",
       "L 289.491434 206.077802 \n",
       "L 291.651771 207.034402 \n",
       "L 293.812109 203.807419 \n",
       "L 295.763381 202.0559 \n",
       "L 297.923718 196.539345 \n",
       "L 300.014367 194.556607 \n",
       "L 302.174704 191.604919 \n",
       "L 304.265353 185.40307 \n",
       "L 306.42569 176.802214 \n",
       "L 308.586028 190.943564 \n",
       "L 310.676676 188.821563 \n",
       "L 314.927663 180.920441 \n",
       "L 317.088 179.365562 \n",
       "L 319.248337 184.834429 \n",
       "L 321.199609 183.644141 \n",
       "L 323.359946 182.557967 \n",
       "L 325.450595 187.089233 \n",
       "L 327.610933 192.379699 \n",
       "L 329.701581 196.061329 \n",
       "L 331.861919 191.518094 \n",
       "L 334.022256 191.493395 \n",
       "L 336.112905 191.173072 \n",
       "L 338.273242 185.032969 \n",
       "L 340.363891 188.047353 \n",
       "L 344.684565 188.607634 \n",
       "L 346.635838 186.434906 \n",
       "L 348.796175 185.996789 \n",
       "L 350.886824 186.312173 \n",
       "L 353.047161 189.504768 \n",
       "L 355.13781 189.151196 \n",
       "L 357.298147 190.297787 \n",
       "L 359.458484 192.851065 \n",
       "L 361.549133 196.805141 \n",
       "L 363.70947 194.733678 \n",
       "L 367.960456 199.841184 \n",
       "L 370.120794 198.070665 \n",
       "L 372.141754 195.489079 \n",
       "L 374.302091 198.637216 \n",
       "L 376.39274 196.100277 \n",
       "L 378.553078 196.557964 \n",
       "L 380.643726 199.34702 \n",
       "L 382.804064 201.6611 \n",
       "L 384.964401 202.727135 \n",
       "L 387.05505 201.992823 \n",
       "L 389.215387 202.321316 \n",
       "L 391.306036 204.007669 \n",
       "L 393.466373 198.516762 \n",
       "L 395.62671 196.307367 \n",
       "L 397.577983 196.684117 \n",
       "L 399.73832 199.134421 \n",
       "L 401.828969 200.249853 \n",
       "L 403.989306 197.919053 \n",
       "L 406.079955 204.024958 \n",
       "L 408.240292 203.747762 \n",
       "L 410.400629 201.760845 \n",
       "L 412.491278 200.3116 \n",
       "L 414.651615 200.939517 \n",
       "L 416.742264 199.440685 \n",
       "L 418.902601 201.426462 \n",
       "L 421.062939 203.001481 \n",
       "L 423.014211 202.560324 \n",
       "L 425.174548 202.997111 \n",
       "L 427.265197 203.129154 \n",
       "L 431.516183 202.711746 \n",
       "L 433.67652 199.800526 \n",
       "L 435.836858 199.503381 \n",
       "L 437.927506 196.716795 \n",
       "L 440.087844 195.646961 \n",
       "L 442.178493 190.656678 \n",
       "L 444.33883 180.17226 \n",
       "L 446.499167 180.634316 \n",
       "L 448.450439 178.735554 \n",
       "L 450.610776 170.421584 \n",
       "L 452.701425 157.241014 \n",
       "L 454.861763 154.009471 \n",
       "L 456.952411 160.365023 \n",
       "L 459.112749 172.020731 \n",
       "L 461.273086 180.717342 \n",
       "L 463.363735 183.628181 \n",
       "L 465.524072 177.362685 \n",
       "L 467.614721 176.168787 \n",
       "L 469.775058 174.387059 \n",
       "L 471.935395 189.616292 \n",
       "L 473.956356 190.559023 \n",
       "L 476.116693 184.556473 \n",
       "L 478.207342 185.802809 \n",
       "L 480.367679 186.215088 \n",
       "L 482.458328 185.968291 \n",
       "L 484.618665 185.023469 \n",
       "L 486.779002 183.006724 \n",
       "L 488.869651 184.541654 \n",
       "L 491.029989 182.721738 \n",
       "L 493.120637 179.880625 \n",
       "L 495.280975 182.661891 \n",
       "L 497.441312 181.606876 \n",
       "L 499.392584 180.038317 \n",
       "L 501.552921 180.403478 \n",
       "L 503.64357 181.692561 \n",
       "L 505.803908 182.404645 \n",
       "L 510.054894 179.443648 \n",
       "L 512.215231 177.775914 \n",
       "L 514.30588 178.001432 \n",
       "L 516.466217 177.157876 \n",
       "L 518.556866 178.604651 \n",
       "L 520.717203 178.795021 \n",
       "L 522.87754 175.495651 \n",
       "L 524.828813 179.702414 \n",
       "L 529.079799 183.06866 \n",
       "L 531.240136 182.817113 \n",
       "L 533.330785 187.52982 \n",
       "L 535.491122 186.979228 \n",
       "L 537.651459 189.85093 \n",
       "L 539.742108 188.025124 \n",
       "L 541.902445 192.17774 \n",
       "L 543.993094 192.454936 \n",
       "L 546.153431 194.246353 \n",
       "L 548.313769 192.523712 \n",
       "L 550.265041 185.752842 \n",
       "L 552.425378 182.906599 \n",
       "L 554.516027 183.142567 \n",
       "L 556.676364 186.55555 \n",
       "L 558.767013 185.032209 \n",
       "L 563.087687 186.792278 \n",
       "L 567.338674 185.97874 \n",
       "L 569.429323 187.063204 \n",
       "L 571.58966 183.678719 \n",
       "L 573.749997 185.076857 \n",
       "L 575.770958 186.905132 \n",
       "L 577.931295 189.375005 \n",
       "L 580.021944 187.289292 \n",
       "L 582.182281 187.436155 \n",
       "L 584.27293 184.922205 \n",
       "L 586.433267 178.741064 \n",
       "L 588.593604 177.113418 \n",
       "L 590.684253 180.488214 \n",
       "L 592.84459 180.3651 \n",
       "L 594.935239 177.187894 \n",
       "L 597.095576 175.643084 \n",
       "L 599.255914 175.453094 \n",
       "L 601.207186 174.958929 \n",
       "L 603.367523 176.235093 \n",
       "L 605.458172 176.141048 \n",
       "L 607.618509 172.937434 \n",
       "L 609.709158 173.39873 \n",
       "L 611.869495 177.0815 \n",
       "L 614.029832 174.296623 \n",
       "L 616.120481 173.836277 \n",
       "L 618.280819 174.232027 \n",
       "L 620.371467 173.917593 \n",
       "L 622.531805 172.475757 \n",
       "L 624.692142 177.763944 \n",
       "L 626.643414 175.847513 \n",
       "L 630.8944 183.736856 \n",
       "L 633.054738 181.088963 \n",
       "L 635.145386 177.057561 \n",
       "L 637.305724 179.819593 \n",
       "L 639.466061 180.790452 \n",
       "L 641.55671 184.167481 \n",
       "L 643.717047 186.6546 \n",
       "L 645.807696 181.755651 \n",
       "L 647.968033 182.935062 \n",
       "L 650.12837 179.773407 \n",
       "L 652.079643 179.318644 \n",
       "L 654.23998 179.446794 \n",
       "L 656.330629 178.488969 \n",
       "L 658.490966 180.744349 \n",
       "L 660.581615 180.791886 \n",
       "L 662.741952 179.101399 \n",
       "L 664.902289 182.35334 \n",
       "L 666.992938 182.531952 \n",
       "L 669.153275 184.274253 \n",
       "L 671.243924 184.067124 \n",
       "L 673.404261 185.107092 \n",
       "L 673.404261 185.107092 \n",
       "\" clip-path=\"url(#pe341f1dec0)\" style=\"fill: none; stroke: #d62728; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 34.240625 244.078125 \n",
       "L 34.240625 22.318125 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 703.840625 244.078125 \n",
       "L 703.840625 22.318125 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 34.240625 244.078125 \n",
       "L 703.840625 244.078125 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 34.240625 22.318125 \n",
       "L 703.840625 22.318125 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"text_19\">\n",
       "    <!-- China's Stock Market -->\n",
       "    <g transform=\"translate(306.086563 16.318125) scale(0.12 -0.12)\">\n",
       "     <defs>\n",
       "      <path id=\"DejaVuSans-43\" d=\"M 4122 4306 \n",
       "L 4122 3641 \n",
       "Q 3803 3938 3442 4084 \n",
       "Q 3081 4231 2675 4231 \n",
       "Q 1875 4231 1450 3742 \n",
       "Q 1025 3253 1025 2328 \n",
       "Q 1025 1406 1450 917 \n",
       "Q 1875 428 2675 428 \n",
       "Q 3081 428 3442 575 \n",
       "Q 3803 722 4122 1019 \n",
       "L 4122 359 \n",
       "Q 3791 134 3420 21 \n",
       "Q 3050 -91 2638 -91 \n",
       "Q 1578 -91 968 557 \n",
       "Q 359 1206 359 2328 \n",
       "Q 359 3453 968 4101 \n",
       "Q 1578 4750 2638 4750 \n",
       "Q 3056 4750 3426 4639 \n",
       "Q 3797 4528 4122 4306 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n",
       "L 1178 3500 \n",
       "L 1178 0 \n",
       "L 603 0 \n",
       "L 603 3500 \n",
       "z\n",
       "M 603 4863 \n",
       "L 1178 4863 \n",
       "L 1178 4134 \n",
       "L 603 4134 \n",
       "L 603 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \n",
       "Q 1497 1759 1228 1600 \n",
       "Q 959 1441 959 1056 \n",
       "Q 959 750 1161 570 \n",
       "Q 1363 391 1709 391 \n",
       "Q 2188 391 2477 730 \n",
       "Q 2766 1069 2766 1631 \n",
       "L 2766 1759 \n",
       "L 2194 1759 \n",
       "z\n",
       "M 3341 1997 \n",
       "L 3341 0 \n",
       "L 2766 0 \n",
       "L 2766 531 \n",
       "Q 2569 213 2275 61 \n",
       "Q 1981 -91 1556 -91 \n",
       "Q 1019 -91 701 211 \n",
       "Q 384 513 384 1019 \n",
       "Q 384 1609 779 1909 \n",
       "Q 1175 2209 1959 2209 \n",
       "L 2766 2209 \n",
       "L 2766 2266 \n",
       "Q 2766 2663 2505 2880 \n",
       "Q 2244 3097 1772 3097 \n",
       "Q 1472 3097 1187 3025 \n",
       "Q 903 2953 641 2809 \n",
       "L 641 3341 \n",
       "Q 956 3463 1253 3523 \n",
       "Q 1550 3584 1831 3584 \n",
       "Q 2591 3584 2966 3190 \n",
       "Q 3341 2797 3341 1997 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-27\" d=\"M 1147 4666 \n",
       "L 1147 2931 \n",
       "L 616 2931 \n",
       "L 616 4666 \n",
       "L 1147 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n",
       "L 2834 2853 \n",
       "Q 2591 2978 2328 3040 \n",
       "Q 2066 3103 1784 3103 \n",
       "Q 1356 3103 1142 2972 \n",
       "Q 928 2841 928 2578 \n",
       "Q 928 2378 1081 2264 \n",
       "Q 1234 2150 1697 2047 \n",
       "L 1894 2003 \n",
       "Q 2506 1872 2764 1633 \n",
       "Q 3022 1394 3022 966 \n",
       "Q 3022 478 2636 193 \n",
       "Q 2250 -91 1575 -91 \n",
       "Q 1294 -91 989 -36 \n",
       "Q 684 19 347 128 \n",
       "L 347 722 \n",
       "Q 666 556 975 473 \n",
       "Q 1284 391 1588 391 \n",
       "Q 1994 391 2212 530 \n",
       "Q 2431 669 2431 922 \n",
       "Q 2431 1156 2273 1281 \n",
       "Q 2116 1406 1581 1522 \n",
       "L 1381 1569 \n",
       "Q 847 1681 609 1914 \n",
       "Q 372 2147 372 2553 \n",
       "Q 372 3047 722 3315 \n",
       "Q 1072 3584 1716 3584 \n",
       "Q 2034 3584 2315 3537 \n",
       "Q 2597 3491 2834 3397 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-53\" d=\"M 3425 4513 \n",
       "L 3425 3897 \n",
       "Q 3066 4069 2747 4153 \n",
       "Q 2428 4238 2131 4238 \n",
       "Q 1616 4238 1336 4038 \n",
       "Q 1056 3838 1056 3469 \n",
       "Q 1056 3159 1242 3001 \n",
       "Q 1428 2844 1947 2747 \n",
       "L 2328 2669 \n",
       "Q 3034 2534 3370 2195 \n",
       "Q 3706 1856 3706 1288 \n",
       "Q 3706 609 3251 259 \n",
       "Q 2797 -91 1919 -91 \n",
       "Q 1588 -91 1214 -16 \n",
       "Q 841 59 441 206 \n",
       "L 441 856 \n",
       "Q 825 641 1194 531 \n",
       "Q 1563 422 1919 422 \n",
       "Q 2459 422 2753 634 \n",
       "Q 3047 847 3047 1241 \n",
       "Q 3047 1584 2836 1778 \n",
       "Q 2625 1972 2144 2069 \n",
       "L 1759 2144 \n",
       "Q 1053 2284 737 2584 \n",
       "Q 422 2884 422 3419 \n",
       "Q 422 4038 858 4394 \n",
       "Q 1294 4750 2059 4750 \n",
       "Q 2388 4750 2728 4690 \n",
       "Q 3069 4631 3425 4513 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \n",
       "L 3122 2828 \n",
       "Q 2878 2963 2633 3030 \n",
       "Q 2388 3097 2138 3097 \n",
       "Q 1578 3097 1268 2742 \n",
       "Q 959 2388 959 1747 \n",
       "Q 959 1106 1268 751 \n",
       "Q 1578 397 2138 397 \n",
       "Q 2388 397 2633 464 \n",
       "Q 2878 531 3122 666 \n",
       "L 3122 134 \n",
       "Q 2881 22 2623 -34 \n",
       "Q 2366 -91 2075 -91 \n",
       "Q 1284 -91 818 406 \n",
       "Q 353 903 353 1747 \n",
       "Q 353 2603 823 3093 \n",
       "Q 1294 3584 2113 3584 \n",
       "Q 2378 3584 2631 3529 \n",
       "Q 2884 3475 3122 3366 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-6b\" d=\"M 581 4863 \n",
       "L 1159 4863 \n",
       "L 1159 1991 \n",
       "L 2875 3500 \n",
       "L 3609 3500 \n",
       "L 1753 1863 \n",
       "L 3688 0 \n",
       "L 2938 0 \n",
       "L 1159 1709 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "     </defs>\n",
       "     <use xlink:href=\"#DejaVuSans-43\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-68\" x=\"69.824219\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-69\" x=\"133.203125\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-6e\" x=\"160.986328\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-61\" x=\"224.365234\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-27\" x=\"285.644531\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-73\" x=\"313.134766\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-20\" x=\"365.234375\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-53\" x=\"397.021484\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-74\" x=\"460.498047\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-6f\" x=\"499.707031\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-63\" x=\"560.888672\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-6b\" x=\"615.869141\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-20\" x=\"673.779297\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-4d\" x=\"705.566406\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-61\" x=\"791.845703\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-72\" x=\"853.125\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-6b\" x=\"894.238281\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-65\" x=\"948.523438\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-74\" x=\"1010.046875\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"legend_1\">\n",
       "    <g id=\"patch_7\">\n",
       "     <path d=\"M 41.240625 89.30875 \n",
       "L 134.6 89.30875 \n",
       "Q 136.6 89.30875 136.6 87.30875 \n",
       "L 136.6 29.318125 \n",
       "Q 136.6 27.318125 134.6 27.318125 \n",
       "L 41.240625 27.318125 \n",
       "Q 39.240625 27.318125 39.240625 29.318125 \n",
       "L 39.240625 87.30875 \n",
       "Q 39.240625 89.30875 41.240625 89.30875 \n",
       "z\n",
       "\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_37\">\n",
       "     <path d=\"M 43.240625 35.416562 \n",
       "L 53.240625 35.416562 \n",
       "L 63.240625 35.416562 \n",
       "\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_20\">\n",
       "     <!-- My_portfolio -->\n",
       "     <g transform=\"translate(71.240625 38.916562) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n",
       "Q 1816 -950 1584 -1140 \n",
       "Q 1353 -1331 966 -1331 \n",
       "L 506 -1331 \n",
       "L 506 -850 \n",
       "L 844 -850 \n",
       "Q 1081 -850 1212 -737 \n",
       "Q 1344 -625 1503 -206 \n",
       "L 1606 56 \n",
       "L 191 3500 \n",
       "L 800 3500 \n",
       "L 1894 763 \n",
       "L 2988 3500 \n",
       "L 3597 3500 \n",
       "L 2059 -325 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-5f\" d=\"M 3263 -1063 \n",
       "L 3263 -1509 \n",
       "L -63 -1509 \n",
       "L -63 -1063 \n",
       "L 3263 -1063 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n",
       "L 1159 -1331 \n",
       "L 581 -1331 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2969 \n",
       "Q 1341 3281 1617 3432 \n",
       "Q 1894 3584 2278 3584 \n",
       "Q 2916 3584 3314 3078 \n",
       "Q 3713 2572 3713 1747 \n",
       "Q 3713 922 3314 415 \n",
       "Q 2916 -91 2278 -91 \n",
       "Q 1894 -91 1617 61 \n",
       "Q 1341 213 1159 525 \n",
       "z\n",
       "M 3116 1747 \n",
       "Q 3116 2381 2855 2742 \n",
       "Q 2594 3103 2138 3103 \n",
       "Q 1681 3103 1420 2742 \n",
       "Q 1159 2381 1159 1747 \n",
       "Q 1159 1113 1420 752 \n",
       "Q 1681 391 2138 391 \n",
       "Q 2594 391 2855 752 \n",
       "Q 3116 1113 3116 1747 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-66\" d=\"M 2375 4863 \n",
       "L 2375 4384 \n",
       "L 1825 4384 \n",
       "Q 1516 4384 1395 4259 \n",
       "Q 1275 4134 1275 3809 \n",
       "L 1275 3500 \n",
       "L 2222 3500 \n",
       "L 2222 3053 \n",
       "L 1275 3053 \n",
       "L 1275 0 \n",
       "L 697 0 \n",
       "L 697 3053 \n",
       "L 147 3053 \n",
       "L 147 3500 \n",
       "L 697 3500 \n",
       "L 697 3744 \n",
       "Q 697 4328 969 4595 \n",
       "Q 1241 4863 1831 4863 \n",
       "L 2375 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \n",
       "L 1178 4863 \n",
       "L 1178 0 \n",
       "L 603 0 \n",
       "L 603 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-4d\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-79\" x=\"86.279297\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-5f\" x=\"145.458984\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-70\" x=\"195.458984\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6f\" x=\"258.935547\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-72\" x=\"320.117188\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-74\" x=\"361.230469\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-66\" x=\"400.439453\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6f\" x=\"435.644531\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6c\" x=\"496.826172\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-69\" x=\"524.609375\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6f\" x=\"552.392578\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_38\">\n",
       "     <path d=\"M 43.240625 50.372812 \n",
       "L 53.240625 50.372812 \n",
       "L 63.240625 50.372812 \n",
       "\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_21\">\n",
       "     <!-- Pmax -->\n",
       "     <g transform=\"translate(71.240625 53.872812) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-50\" d=\"M 1259 4147 \n",
       "L 1259 2394 \n",
       "L 2053 2394 \n",
       "Q 2494 2394 2734 2622 \n",
       "Q 2975 2850 2975 3272 \n",
       "Q 2975 3691 2734 3919 \n",
       "Q 2494 4147 2053 4147 \n",
       "L 1259 4147 \n",
       "z\n",
       "M 628 4666 \n",
       "L 2053 4666 \n",
       "Q 2838 4666 3239 4311 \n",
       "Q 3641 3956 3641 3272 \n",
       "Q 3641 2581 3239 2228 \n",
       "Q 2838 1875 2053 1875 \n",
       "L 1259 1875 \n",
       "L 1259 0 \n",
       "L 628 0 \n",
       "L 628 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-6d\" d=\"M 3328 2828 \n",
       "Q 3544 3216 3844 3400 \n",
       "Q 4144 3584 4550 3584 \n",
       "Q 5097 3584 5394 3201 \n",
       "Q 5691 2819 5691 2113 \n",
       "L 5691 0 \n",
       "L 5113 0 \n",
       "L 5113 2094 \n",
       "Q 5113 2597 4934 2840 \n",
       "Q 4756 3084 4391 3084 \n",
       "Q 3944 3084 3684 2787 \n",
       "Q 3425 2491 3425 1978 \n",
       "L 3425 0 \n",
       "L 2847 0 \n",
       "L 2847 2094 \n",
       "Q 2847 2600 2669 2842 \n",
       "Q 2491 3084 2119 3084 \n",
       "Q 1678 3084 1418 2786 \n",
       "Q 1159 2488 1159 1978 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2956 \n",
       "Q 1356 3278 1631 3431 \n",
       "Q 1906 3584 2284 3584 \n",
       "Q 2666 3584 2933 3390 \n",
       "Q 3200 3197 3328 2828 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \n",
       "L 2247 1797 \n",
       "L 3578 0 \n",
       "L 2900 0 \n",
       "L 1881 1375 \n",
       "L 863 0 \n",
       "L 184 0 \n",
       "L 1544 1831 \n",
       "L 300 3500 \n",
       "L 978 3500 \n",
       "L 1906 2253 \n",
       "L 2834 3500 \n",
       "L 3513 3500 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-50\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6d\" x=\"60.302734\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-61\" x=\"157.714844\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-78\" x=\"218.994141\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_39\">\n",
       "     <path d=\"M 43.240625 65.050937 \n",
       "L 53.240625 65.050937 \n",
       "L 63.240625 65.050937 \n",
       "\" style=\"fill: none; stroke: #2ca02c; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_22\">\n",
       "     <!-- P1 -->\n",
       "     <g transform=\"translate(71.240625 68.550937) scale(0.1 -0.1)\">\n",
       "      <use xlink:href=\"#DejaVuSans-50\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-31\" x=\"60.302734\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_40\">\n",
       "     <path d=\"M 43.240625 79.729062 \n",
       "L 53.240625 79.729062 \n",
       "L 63.240625 79.729062 \n",
       "\" style=\"fill: none; stroke: #d62728; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_23\">\n",
       "     <!-- Market -->\n",
       "     <g transform=\"translate(71.240625 83.229062) scale(0.1 -0.1)\">\n",
       "      <use xlink:href=\"#DejaVuSans-4d\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-61\" x=\"86.279297\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-72\" x=\"147.558594\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6b\" x=\"188.671875\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-65\" x=\"242.957031\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-74\" x=\"304.480469\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pe341f1dec0\">\n",
       "   <rect x=\"34.240625\" y=\"22.318125\" width=\"669.6\" height=\"221.76\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 1200x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画图\n",
    "fig = plt.figure(figsize=(12, 4))\n",
    "plt.plot(MYPORT['price_portfolio'],label='My_portfolio')  \n",
    "plt.title(\"China's Stock Market\") \n",
    "plt.xlabel('Month') \n",
    "plt.ylabel('Return') \n",
    "plt.plot(MYPORT['Pmax_price'],label='Pmax')  \n",
    "plt.plot(MYPORT['P1_price'],label='P1')  \n",
    "plt.plot(MYPORT['Market_price'],label='Market')  \n",
    "#图例\n",
    "plt.legend(loc='upper left')\n",
    "# 添加网格线\n",
    "plt.grid(True)\n",
    "plt.show();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 最大回撤\n",
    "\n",
    "即最大损失是多少，这是衡量一个策略好不好的重要指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum Drawdown: -0.5167687396538915\n"
     ]
    }
   ],
   "source": [
    "# 计算累积收益率\n",
    "MYPORT['cumulative_return'] = (1 + MYPORT['My_portfolio']).cumprod()\n",
    "# 计算滚动最大值\n",
    "MYPORT['roll_max'] = MYPORT['cumulative_return'].cummax()#历史上最大点\n",
    "# 计算回撤\n",
    "MYPORT['drawdown'] = MYPORT['cumulative_return'] / MYPORT['roll_max'] - 1#当前和历史上最大值的差值\n",
    "# 计算最大回撤\n",
    "max_drawdown = MYPORT['drawdown'].min()#找最小，即最小的负收益\n",
    "print(f\"Maximum Drawdown: {max_drawdown}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最大回撤开始时间为： 2014-08-31 00:00:00\n",
      "最大回撤结束时间为： 2015-04-30 00:00:00\n"
     ]
    }
   ],
   "source": [
    "# 找出最大回撤的时间\n",
    "max_drawdown_time = MYPORT['drawdown'].idxmin() # 返回 Series 中最小值的索引\n",
    "max_drawdown_start = MYPORT.loc[:max_drawdown_time, 'cumulative_return'].idxmax() # 这部分代码选择了从数据开始到 max_drawdown_time 时间点之间最大的时间索引\n",
    "#分别返回最大回撤的结束和开始时间\n",
    "print('最大回撤开始时间为：', max_drawdown_start)\n",
    "print('最大回撤结束时间为：',max_drawdown_time)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "但这个回撤时间恰好是大盘涨的最厉害的时候，而这个投资策略却是亏钱的"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
